Skip to the content.

Pages and attributes

A page is a class with [CrudPage]. Its properties decide what the list shows, what can be searched and sorted, and what can be written. The entity is untouched: the engine maps between the two.

[CrudPage]

[CrudPage("cities", Entity = typeof(City),
    Title = "Cities", ItemTitle = "City", Group = "Settings",
    DefaultSort = "Name", LookupText = "Name", Permission = "cities")]
public class CityModel { ... }
Property Meaning Default
id (constructor) Route key: /api/crud/{id} required
Entity The EF entity it reads and writes required
ReadEntity A separate read model (SQL view, read table) for lists and gets the entity
Title / ItemTitle Plural / singular names (translated) the id
Group Menu group in UIs none
Permission Permission prefix: crud:{permission}:{action} the id
DefaultSort "Name", "Name desc, Id" the key
LookupText Text shown when other pages pick a row Name, else Title, else the first text column
Tenancy Auto, Tenant, Shared, SharedWithTenantRows (tenancy) Auto
Delete Auto, Hard, Soft (delete) Auto
ApiReadOnly The HTTP API only reads the page; code still writes it (security) false

The model needs a key: [Key], or a property named Id. It needs a public parameterless constructor.

Mapping

A model property maps to the entity property with the same name. Names that start with a navigation are flattened: CategoryName reads Category.Name, in SQL (a join, no extra query).

[Grid(Title = "Category", Sortable = true)]
public string? CategoryName { get; set; }      // e.Category.Name

Columns: [Grid]

Property Meaning
Title Column title (translated)
Sortable May be sorted on (sort=name:desc); only sortable columns are accepted
Order Position
Format .NET format for numbers, e.g. "N0"

Form fields: [Field]

Only [Field] properties are ever written, so extra JSON properties can’t change other columns (over-posting).

Property Meaning
Label Field label (translated)
Type Auto, Text, TextArea, Number, Date, DateTime, … (input hint for UIs)
Order Position in forms
Placeholder Input hint

Validation uses normal DataAnnotations ([Required], [Range], [StringLength], …) plus:

All errors come back together as one 400 with errors per field.

Required and initial values. A field is required in the schema when it has [Required], or when its type can’t be empty: a non-nullable number, enum or date (a bool is a checkbox, so it isn’t). Make it nullable (int?, Priority?) to allow “empty”. A value the page model starts with becomes the field’s default, and forms prefill it on new rows:

[Field] public Priority Priority { get; set; } = Priority.Normal;   // "required": true, "default": 2

Null, empty text and the type’s own default (0, or the enum member whose value is 0) count as no initial value. Override PageSchemaBuilder.CannotBeEmpty or DefaultValue to change either rule.

Enums are sent and accepted as numbers (names are accepted too). The schema lists their choices (on the field, the search filter and the grid column) so a UI can show a drop-down and labels:

public enum Priority { Low = 1, Normal = 2, [Display(Name = "Very high")] High = 3 }
"choices": [ { "value": 1, "text": "Low" }, { "value": 2, "text": "Normal" }, { "value": 3, "text": "Very high" } ]

Labels are translated like any other text. Override PageSchemaBuilder.BuildChoices to change them.

[Search(Op.Contains)]            public string Name { get; set; }       // f.name=riy
[Search(Op.Between)]             public int Population { get; set; }    // f.population.from=1000&f.population.to=5000
[Search(Op.In)]                  public Status Status { get; set; }     // f.status=Active,Draft
[Search(Op.IsNull)]              public int? Stock { get; set; }        // f.stock=true
[Search(Op.Gte)]                 public DateOnly Released { get; set; } // f.released=2026-01-01

Operators: Eq (default), NotEq, Contains, StartsWith (text only), Gt, Gte, Lt, Lte, Between, In, IsNull. Values are parsed to the property type and sent as SQL parameters; nothing is evaluated in memory.

Arabic text can match across spellings (أحمد / احمد, ة / ه, diacritics): [Search(Op.Contains, Normalization = TextNormalization.Arabic)] (localization).

Text case follows the database collation. Change it per field with [Search(Op.Contains, Case = TextCase.Insensitive)] or for the whole app with o.CaseInsensitiveText = true.

Fixed filters: [Filter]

[Filter(Status.Active)] public Status Status { get; set; }   // the page only ever sees active rows

Applied to every read and write of the page, like a built-in WHERE.

Computed values: [Computed]

Values computed in SQL by a mapper subclass (found automatically):

public class CategoryMapper : PageMapper<CategoryModel, Category>
{
    public CategoryMapper()
    {
        Compute(m => m.ProductCount, e => e.Products.Count);
        Compute(m => m.CanDelete, e => !e.Products.Any());
    }
}

Read models (CQRS)

Point ReadEntity at a view or read table: lists, gets and lookups read from it; creates, updates and deletes still go to Entity. Columns and search map to the read type, fields to the entity. See also read replicas in Security and multi-tenancy.

Mistakes are caught early

Unmapped search or sort properties, a Contains on a number, an unknown DefaultSort field and similar mistakes fail the build (compile-time checks) and, if they get past it, the app’s startup, never a user’s request.