Entity Framework use foreign key names for navigation properties

c# entity-framework-6

Question

How can we get the templating script when using DB first approach in EF 6 to use the foreign key names to generate the entity (navigational) property names rather than the format of Entity1, Entity2 etc?

An example where this is an issue is if you have a table that has columns like createdby, updayedby etc and these have foreign keys to a user table EF will use the alphabetical order of the foreign keys to generate the properties of the table entity and you end up with User, User1 as properties. This becomes a big issue when you later add a new FK to the user table with a name that causes User1 not to be the updatedby user anymore because the new FK appears above the updatedby FK of that generated User1 before!

Thanks!

1
1
10/24/2017 3:34:16 PM

Popular Answer

For code first from database, you can use https://www.nuget.org/packages/EntityFramework.CodeTemplates.CSharp which will add the tt templates used to your project.

1
10/30/2017 6:08:56 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow