Skip to the content.

Compile-time checks and generated names

Both ship inside the Abstractions package: any project that uses the attributes gets them, with no setup.

Checks (analyzers)

The startup rules, reported in the editor and failing the build:

Id Severity Rule
CRUD001 Error [CrudPage] without Entity
CRUD002 Error no key (no [Key], no Id) or more than one [Key]
CRUD003 Error a key, [Search], sortable column, [Filter] or [Unique] that doesn’t map to the (read) entity
CRUD004 Error Contains / StartsWith on a non-text property
CRUD005 Error [Parent] without [Field]
CRUD006 Error a DefaultSort field that doesn’t map
CRUD007 Error LookupText that isn’t a mapped text property
CRUD008 Error [Lookup] / [Parent] target that isn’t a [CrudPage] model
CRUD009 Error page model without a public parameterless constructor
CRUD010 Error two pages with the same id
CRUD011 Warning Delete = Soft without a visible flag (ignore it if you map your own interface)
CRUD012 Warning a bool that looks like a misspelled soft-delete flag (IsDelete)
CRUD013 Error soft-delete flag of the wrong type, used as a [Field], or missing on the ReadEntity
CRUD014 Warning [OwnRows] on an entity without a visible creator field (ignore it if you map your own interface)
CRUD015 Error [ScopeBy] property that isn’t on the entity, or an empty claim type
CRUD016 Error [Restricted] on the key, or a name that isn’t letters, digits and -
CRUD017 Warning [Restricted] on a non-nullable value type (hidden values come back as the default, e.g. 0)

Silence one the usual way (#pragma warning disable CRUD012 or .editorconfig: dotnet_diagnostic.CRUD012.severity = none).

Quick fixes

Where the fix is clear, the light bulb (Ctrl+. in Visual Studio and VS Code) offers it. Fix-all works for the document, project or solution.

Id Quick fix
CRUD005 Add [Field] next to [Parent]
CRUD009 Add a public parameterless constructor (or make the existing one public). Not offered for primary constructors
CRUD011 Add public bool IsDeleted { get; set; } to the entity, also when it’s in another project (your Domain)
CRUD012 Rename the property to IsDeleted everywhere it’s used. Add a migration afterwards: the column is renamed too
CRUD013 Remove [Field] from the soft-delete flag
CRUD014 Add public string? CreatedBy { get; set; } to the entity
CRUD016 Remove [Restricted] from the key, or use a valid name ("my note" becomes "my-note")
CRUD017 Make the property nullable (decimal becomes decimal?)

Entity fixes need the entity’s source in the same solution (not a package). The fixes are in a separate assembly next to the analyzers; only the IDE loads it, so command-line builds are unchanged.

Generated names

For every page, in the page model’s namespace:

CrudPages.Course.Id                       // "courses"
CrudPages.Course.Permission               // "courses"
CrudPages.Course.Fields.DurationWeeks     // "durationWeeks": the JSON / filter / sort name
CrudPages.Course.Claims.View              // "crud:courses:view"
CrudPages.Course.Claims.All               // "crud:courses:*"

CourseModel becomes Course. Use them for links ($"/admin/{CrudPages.Course.Id}"), filters ($"f.{CrudPages.Course.Fields.Name}=..."), claims in tests and seed data; a renamed property updates them.

The page catalog

The generator also writes [assembly: CrudPageCatalog(typeof(...), ...)]: the types AddPagesFrom registers. Startup reads it instead of scanning every type, and trimming keeps those types. o.UseGeneratedCatalog = false goes back to scanning. The engine’s tests require both ways to register exactly the same services.

Field writers

For every page the generator also writes a small class that saves form fields with direct assignments (entity.Name = model.Name;), so saving needs no reflection. It covers every [Field] that maps to a public, settable entity property of the same or a wider type (int → int?, int → long, same enum). Anything else (private setters, init-only properties, narrowing conversions, flattened paths) is left to the engine, field by field, exactly as before. The engine decides which fields are written (key, computed values and the tenant never are), so the writers change speed, not behavior. The engine’s tests compare both ways on every test page. o.UseGeneratedWriters = false turns them off.

Still built at startup: the page metadata (from the attributes) and the read projection, which stays an expression because the database runs it.