Roadmap › Entity Framework (EF6 & EF Core) › Module: Relationships and Modelling
Lessons in this course (15)
6. Owned types, complex types, value conversions and inheritance
IntermediateMediumLesson 6 of 15
csharp
// Value object stored in the owner's table (Address_City, Address_Street columns)
b.Entity<Customer>().OwnsOne(c => c.Address); // owned entity
b.Entity<Customer>().ComplexProperty(c => c.Address); // EF Core 8 complex type (true value semantics)
// Enum stored as string
b.Entity<Order>().Property(o => o.Status).HasConversion<string>().HasMaxLength(20);
// JSON column (EF Core 7+)
b.Entity<Order>().OwnsOne(o => o.Metadata, m => m.ToJson());Inheritance strategies:
| Strategy | Tables | Pros/cons |
|---|---|---|
| TPH — Table per Hierarchy (default) | One table + discriminator column | Fastest queries; nullable columns |
| TPT — Table per Type | Base table + one per derived type | Normalised; joins make it slower |
| TPC — Table per Concrete type (EF 7) | One table per concrete class | No joins for concrete queries; IDs must be unique across tables |