I have an entity with hundreds of properties. While it is good in database, in classes it is inconvenient. The question is, how can I group some properties of the class into other classes so it would be more convenient in programming, while keeping only one table.
Pseudocode example:
class Work {
WorkVolumes WorkVolumes;
...
SomeOtherGroupOfProperties SomeOtherGroup;
}
class WorkVolumes {
float VolumeOfWorkType1;
float VolumeOfWorkType2;
...
float VolumeEtc;
}
class SomeOtherGroupOfProperties {
int SomeOtherProperty;
...
}
While in database there is only table Work with columns VolumeOfWorkType1, VolumeOfWorkType2, VolumeEtc, SomeOtherProperty, ...
see "Automatic table splitting for owned entity types" here: https://blogs.msdn.microsoft.com/dotnet/2017/06/28/announcing-ef-core-2-0-preview-2/
for the following model only one table is created:
modelBuilder.Entity<Order>().OwnsOne( p => p.OrderDetails, cb => { cb.OwnsOne(c => c.BillingAddress); cb.OwnsOne(c => c.ShippingAddress); }); public class Order { public int Id { get; set; } public OrderDetails OrderDetails { get; set; } } public class OrderDetails { public StreetAddress BillingAddress { get; set; } public StreetAddress ShippingAddress { get; set; } } public class StreetAddress { public string Street { get; set; } public string City { get; set; } }