Skip to content

Property extensions

Import Cratis.Arc.EntityFrameworkCore for these extensions on EF’s PropertyBuilder.

AsGuid(DatabaseType databaseType) adds a Guid/string converter for SQLite using the D format and Guid.Parse. For plain Guid properties on PostgreSQL and SQL Server, it leaves the EF provider mapping unchanged. For concept properties it delegates to AsConcept.

BaseDbContext applies Guid conversion to relevant model types. Manual OnModelCreating fragment for a Customer.Id Guid property:

modelBuilder.Entity<Customer>().Property(customer => customer.Id).AsGuid(Database.GetDatabaseType());

This does not specify CHAR(36), collation, or indexes. Guid conversion explains the distinction from migration column types.

AsConcept(DatabaseType databaseType) unwraps ConceptAs<T> to its primitive value and reconstructs the concept on reads. It configures a concept value comparer and does nothing for non-concept properties. Guid concepts use string conversion for SQLite.

Manual model-configuration fragment:

modelBuilder.Entity<Customer>().Property(customer => customer.Id).AsConcept(Database.GetDatabaseType());

Here Customer.Id is a concept property. Use records, not classes, for concept declarations, and nullable concept references for optional values. See concept conversion. BaseDbContext already applies this conversion for relevant model types.

MethodModel typeProvider value
AsPoint()Cratis.Geospatial.PointPlain JSON string
AsLineString()Cratis.Geospatial.LineStringPlain JSON string
AsPolygon()Cratis.Geospatial.PolygonPlain JSON string

These methods take no database argument and are not applied automatically by BaseDbContext. They add a value converter only, without geometry validation, spatial query translation, SQL type selection, or a structural value comparer.

Use the geometry storage-path matrix before combining conversions and migrations. [Json] is a separate property-attribute path with its own serializer options; it is not a synonym for these extensions.