C# and .NET Advanced Data Operations
These examples combine generated School Management APIs into application-sized patterns. Generated source remains the authority for names in your model.
Search page with rows and two facets
var rows = await Q.Schools()
.WithNameContaining("Primary")
.SelectSchoolTypeWith(
Q.SchoolTypesWithMinimalFields().SelectCode().SelectName())
.SelectPlatformWith(Q.PlatformsWithMinimalFields().SelectName())
.FacetBySchoolTypeAs(
"schoolTypes",
Q.SchoolTypesWithMinimalFields()
.WithCodeIn("PRIMARY", "SECONDARY")
.SelectCode().SelectName().CountSchoolsAs("schoolCount"),
includeAllFacets: true)
.FacetByPlatformAs(
"platforms",
Q.PlatformsWithMinimalFields().SelectName().CountSchoolsAs("schoolCount"),
includeAllFacets: false)
.OrderByIdDescending()
.Limit(50)
.Comment("Search schools with dashboard facets")
.Purpose("Render the authorized operations dashboard")
.ExecuteForListAsync(context);
var typeBuckets = rows.Facet("schoolTypes");
var platformBuckets = rows.Facet("platforms");
The two Boolean arguments control include-all independently. The main rows and both named sidecars still share the normalized outer School filter.
Deep graph and per-parent Top-N
var platforms = await Q.Platforms()
.SelectName()
.SelectSchoolListWith(
Q.Schools()
.SelectName()
.SelectSchoolTypeWith(
Q.SchoolTypesWithMinimalFields().SelectCode().SelectName())
.OrderByStudentCapacityDescending()
.Limit(3))
.Comment("Load each platform and its three largest schools")
.Purpose("Render the authorized platform capacity review")
.ExecuteForListAsync(context);
The child limit is per Platform. Verify the ADO.NET provider emits the native partition/window plan instead of reproducing the result with application code.
Grouped and relation analytics
var distribution = await Q.Schools()
.GroupBySchoolType()
.CountAs("schoolCount")
.SumStudentCapacityAs("capacityTotal")
.AvgStudentCapacityAs("capacityAverage")
.Comment("Aggregate school capacity by type")
.Purpose("Build the authorized capacity report")
.ExecuteForRowsAsync(context);
var cards = await Q.SchoolTypesWithMinimalFields()
.SelectCode().SelectName()
.CountSchoolsAs("schoolCount")
.SumStudentCapacityOfSchoolsAs("capacityTotal", Q.Schools())
.Comment("Calculate type-level school metrics")
.Purpose("Render the authorized type cards")
.ExecuteForListAsync(context);
Read grouped aliases from distribution.Rows. Relation aliases decorate typed
parents but are projections, not writable entity properties.
Audited read-modify-save
var school = await Q.Schools()
.WithIdIs(schoolId)
.SelectPlatformWith(Q.PlatformsWithMinimalFields().SelectName())
.SelectSchoolTypeWith(Q.SchoolTypesWithMinimalFields().SelectCode())
.Comment("Load the complete school for capacity approval")
.Purpose("Apply an authorized capacity revision")
.ExecuteForOneAsync(context);
if (school is null) throw new InvalidOperationException("school not found");
school.UpdateStudentCapacity(newCapacity);
school = await school.AuditAs("Approve revised student capacity").SaveAsync(context);
Load all Checker/Fix inputs and keep the returned entity so later saves use the authoritative optimistic version.