Skip to content

Guid conversion

A .NET Guid and a SQL column declaration are different contracts. Arc’s Guid conversion changes the value sent to SQLite; it does not tune indexes, collations, or every EF provider.

BaseDbContext calls ApplyGuidConversion for relevant model types. For manual configuration, this is an OnModelCreating fragment with Cratis.Arc.EntityFrameworkCore and Microsoft.EntityFrameworkCore imported:

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

Here Customer.Id is a Guid property and Database belongs to the context.

DatabaseWhat AsGuid(databaseType) adds
SQLiteA Guid → string converter using ToString("D"), with Guid.Parse on reads
PostgreSQLNo additional conversion for a plain Guid; the EF provider supplies its mapping
SQL ServerNo additional conversion for a plain Guid; the EF provider supplies its mapping

For a Guid-backed concept, AsGuid delegates to AsConcept. SQLite uses string storage for that converter too. Ordinary ConceptAs<Guid> identifiers remain valid in standalone Arc applications.

GuidColumn and AddGuidColumn select these SQL type names independently of the model converter:

PostgreSQLSQL ServerSQLite
UUIDUNIQUEIDENTIFIERBLOB

The SQLite migration helper therefore declares BLOB even though AsGuid supplies strings. Do not interpret the helper as a CHAR(36) declaration or as binary serialization. Review generated migrations and test existing-data compatibility before changing a schema or representation.

Arc’s built-in database detection covers the three providers above. Other EF providers may have their own Guid support, but Arc does not supply MySQL/Oracle optimization or collation guarantees.

See common column types and concept conversion for related contracts.