1

I am using Entity Framework 6 database first. I have modified the T4 file to give my navigation properties meaningful names based off the Foreign Key constraints similar to this solution. However this seems to have screwed up the Associations in the model in my .edmx. I am having to change the navigation properties to match what is actually being generated in my entity classes every time I update my model from database.

My question is, how are the model Associations generated? Are they from the T4 somewhere? or do they come straight from the database constraints?

Community
  • 1
  • 1
koolaide
  • 155
  • 9

1 Answers1

0

You should first choose meaningful names for your constraints in SQL.

Once you have those, you can use the model browser on your .edmx and choose how you want each end of an association named, then regenerate your code.

This info sits in the .edmx and that is where you should modify it. The T4 uses the .edmx to generate the code so if you change the way associations are named in the T4, EF will not recognize them when it's trying to translate code back into SQL.

Radu Porumb
  • 785
  • 5
  • 7
  • Ok, so if I understand correctly. I should be able to remove any custom changes to the T4, update my model from database, then name the navigation properties from the Associations in the .edmx? I will give it a shot thanks. – koolaide Aug 14 '14 at 16:05
  • Yup that did it! Perhaps this is a change from EF6 and the T4 edit is no longer needed? – koolaide Aug 14 '14 at 16:12
  • In theory you should never need to touch the T4. For changes like this and most others, you should only change stuff in the Model Browser/EDMX. – Radu Porumb Aug 14 '14 at 16:22