dnatoli
dnatoli

Reputation: 7012

Meaningful Names for Navigation Properties using Entity Framework

I am using the ADO .NET Entity Framework to import my model from a database. A table in my db has a bunch of foreign keys, all with abstract names e.g. FKDevice132610.

When I import the table into my model, it brings in navigation properties for each foreign key, however they are imported with names based on the table name they link to. If there is more than one foreign key to a certain table, a number is appended on the end.

Ef model

In this case Devices1 is ParentDevices and Devices2 is ChildDevices. Is there a way I can enter this information into my foreign key (say using the description or the name) so that the Entity Framework will import meaningful names for my navigation properties?

Upvotes: 13

Views: 2742

Answers (3)

Ivan Ferrer Villa
Ivan Ferrer Villa

Reputation: 2158

Four years later...
One possible workaround could be to parse the .edmx file using an external tool and replace all texts starting with <NavigationProperty Name= by more meaningful navigation names.
Being XML, is extremely easy to parse and find properties like multiplicity, FK name, etc.

Upvotes: 0

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364349

As I know there is currently no way to do that. This is how current designer works. What is even worse when you rename these properties to correct names updating model from database will sometimes overwrite your changes.

Upvotes: 6

Par6
Par6

Reputation: 389

Wondering if a search on "modelBuilder.Conventions.Remove" will lead you to a solution. I wish I could be more of a help but I am just starting to explore EF. Ran into a similar situation when I had multiple fields referring back to the same ID...and I do not remember what the work around was.

Upvotes: 0

Related Questions