Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 581
Karolis Juodelė Avatar asked Jul 22 '13 18:07

Karolis Juodelė


1 Answers

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.

like image 88
Amin Saqi Avatar answered Oct 14 '22 07:10

Amin Saqi