Skip to main content

C# and .NET Quick Start

This path prepares a generated C# library and a handwritten console or web project. Generated code remains replaceable; application composition and customization live in a separate project.

Release status: public NuGet coordinates and the public .NET generator target have not been announced. Do not guess a package ID or version. After publication, the release notes must identify the runtime package, provider packages, target name, supported target frameworks, and minimum SDK.

1. Prepare the solution

TeaqlOrderReview/
├── model/main.xml
├── generated/OrderReview.Domain/
├── src/OrderReview.App/
└── tests/OrderReview.Tests/
dotnet --info
dotnet new sln -n TeaqlOrderReview
cargo teaql services
cargo teaql evaluate --input model/main.xml

After release, generate with the target returned by the live catalog and add the generated .csproj plus application/test projects to the solution.

2. Create the model

<?xml version="1.0" encoding="UTF-8"?>
<root name="order-review" org="example" data_service="sqlite" version="1.0.0">
<customer_order
order_number="WEB-10001"
_module_key="root" />
</root>

Fix evaluation errors before generation. Generated output should contain a project, Q.cs, E.cs, entity models, typed Requests, and runtime/provider support selected by the model.

3. Inspect and build

find generated/OrderReview.Domain -maxdepth 3 -type f | sort
rg 'Purpose\(|ExecuteForListAsync|AuditAs\(|SaveAsync' generated/OrderReview.Domain
dotnet restore
dotnet build -p:UseSharedCompilation=false
dotnet test -p:UseSharedCompilation=false

Read Q.cs for generated plural entry points and Request sources for exact predicates. Never append s/es, and preserve the human WhoAre/Whose versus non-human WhichAre/With distinction.

4. Initialize trusted context

ADO.NET provider, generated metadata, tenant, actor, permissions, request policy, and audit sinks are registered while building UserContext.

static async Task<UserContext> CreateRequestContextAsync(
Infrastructure infra,
AuthenticatedRequest trusted)
{
var ctx = new UserContext();
// Register generated module/provider and trusted request state with released APIs.
return ctx;
}

Use exact registration methods from the released runtime. Generated execution accepts only ctx; there is no (ctx, service) overload.

5. Execute the first query

After inspecting emitted names:

var orders = await Q.CustomerOrders()
.Comment("Find web orders")
.WithOrderNumberContaining("WEB-")
.OrderByIdAscending()
.Limit(20)
.Purpose("Display the authorized order list")
.ExecuteForListAsync(ctx);

Comment may occur anywhere before Purpose. Purpose returns the executable Request state; terminal methods must not be available before that transition.

6. Save with audit intent

var order = Q.CustomerOrders()
.Comment("Create the first verified order")
.Purpose("Persist an authorized order")
.NewEntity(ctx);

order.UpdateOrderNumber("WEB-10002");
await order.AuditAs("Create the first verified order").SaveAsync(ctx);

Read the generated model for UpdateOrderNumber and all mutation APIs. Missing audit reason, intent, or provider context must fail explicitly.

7. Regenerate

Change KSML, evaluate, regenerate the whole project, rebuild, and rerun provider tests. Review project dependencies, Q.cs, Requests, models, expressions, and runtime wiring. Continue with .NET First Verification and .NET Customization.