Customize Navigation_ naming convention for Owned Type columns
Describe what is not working as expected
I would like a way to customize the Navigation_ part of the convention in owned types:
By convention, EF Core will name the database columns for the properties of the owned entity type following the pattern Navigation_OwnedEntityProperty. Therefore the
StreetAddressproperties will appear in the 'Orders' table with the names 'ShippingAddress_Street' and 'ShippingAddress_City'. Source
Desired Behavior
In the above example, I want the StreetAddress properties to appear in the 'Orders' table as 'Street' and 'City'.
ShipsTo Example
It would simplify the sample code to change ShippingAddress_ to ShipsTo:

vs
modelBuilder.Entity<Order>().OwnsOne(
o => o.ShippingAddress,
prefix: "ShipsTo");
Thoughts? 💭
Further technical details
EF Core version: 2.1 Database Provider: Microsoft.EntityFrameworkCore.SqlServer Operating system: Win 10 IDE: 16.3 Preview 2
A better example is if I complete the ShippingAddress entity which is incomplete (doesn't need to be complete for the documentation, I get that 😊)
modelBuilder.Entity<Order>().OwnsOne(
o => o.ShippingAddress,
sa =>
{
sa.Property(p => p.Street).HasColumnName("ShipsToStreet");
sa.Property(p => p.Street2).HasColumnName("ShipsToStreet2");
sa.Property(p => p.City).HasColumnName("ShipsToCity");
sa.Property(p => p.State).HasColumnName("ShipsToState");
sa.Property(p => p.Zip).HasColumnName("ShipsToZip");
sa.Property(p => p.Country).HasColumnName("ShipsToCountry");
});
vs
modelBuilder.Entity<Order>().OwnsOne(
o => o.ShippingAddress,
prefix: "ShipsTo");
This is something that in the future could be a public convention. Backlogging for now.
Great 👍
If you can point me in the right direction maybe I could implement it 😊? Where do I start looking in the code to add this? Seems pretty straight forward on the surface.
@spottedmahn It is dependent on #214, which is a fairly substantial chunk of work and still requires some design.
I see, thanks! I'll circle back once #214 is complete (only 3 checkboxes to go 😊)
Related to https://github.com/dotnet/efcore/issues/9329
#214 was closed 😊
On the nightly build or RC1 you can try adding your own convention. It would need to implement IForeignKeyOwnershipChangedConvention and IPropertyAddedConvention and perhaps some other interfaces. It's added in ConfigureConventions by calling Conventions.Add(_ => new MyConvention())
There isn't relevant documentation yet, see https://github.com/dotnet/efcore/blob/71b7f6dcc81a6285568305534ea7dd7e4edc7709/src/EFCore/Metadata/Conventions/KeyDiscoveryConvention.cs for an example
@AndriySvyryd @ajcvickers Gentlemen this inability to set up an existing table to have an Owned Type property stops our porting away from EF6 to EF Core. We are heavy users of Complex Types, and in the EDMX model (which was amazing for the teams of all sizes by the way!) we were able to "map" a collection of existing columns "as they were" into a Complex Type. I understand that Owned Types have other useful functionality but there is something important that has been taken away! Please consider implementing a capability to allow for a custom prefix (or lack thereof!) Thank you!
Same. My team have just hit the limits of owned type on Postgres due to limitations of column name sizes. We have so many nested properties that we are starting to get ambiguous column name errors because it cannot distinguish between different props of our types.