Karolis Juodelė
Karolis Juodelė

Reputation: 3771

Renaming navigation properties

Sometimes entity framework generates awful navigation property names. Using the database first approach, what is the best way to fix that?

I am able to edit the t4 templates to my liking, but how would I bind these modified names to actual relations? Should I just write a script to modify the edmx file? Obviously, doing it by hand is is hardly an option.

Upvotes: 8

Views: 4684

Answers (1)

Amin Saqi
Amin Saqi

Reputation: 18977

Yeah, you can. In most of cases you just need to rename that NavPr from the EF model designer and save the model. Then EF renames that NavPr in your DbContext.tt entity classes and it cause no problem.

If you got problems with the ralation name, right-click at the renamed NavPr and select properties. Then change the Association property of it to the actual relation in your database.

If you can't see the relative relation name there, delete that entity and all other entities which has a relation to it, right-click on model designer and choose Update model from database. Then, simply rename that ugly NavPr and save the model.

Upvotes: 2

Related Questions