0

I have a database-first model generated with full primary keys. Database first model works fine. However now I have upgraded my Entity Framework 4.3. I have modified the standard T4 template that comes with EF.

Now when I use Add-Migration initial to the project it is complaining that my entities do not have the Primary keys defined. Which is not true (or to some extent)... looking deeper I have composite keys for which EF expects me to define [Key, Column(0)] on all of the key elements.

System.Data.Entity.Edm.EdmEntitySet: EntityType: EntitySet 'SupplierWarehouses' is based on type 'SupplierWarehouses' that has no keys defined.

The problem I am facing is I trying to modify the WriteProperty method of T4 Template (DbContext) and there seems to be no Entity Key Property on System.Data.Metadata.Edm.EdmProperty object. Now this property is shown from Visual Studio Model Editor so Theory is it should exist.

Appreciate if some one could help me with this

Sanj.

Sanj
  • 3,770
  • 6
  • 26
  • 31

1 Answers1

0

I figured it out System.Data.Metadata.Edm.EdmProperty does not have it this property, it needs to be referred from System.Data.Metadata.Edm.EntityType the actual property is KeyMembers.

I made the change to T4 WriteProperty to accept Entity Object now it works as beauty.

Sanj
  • 3,770
  • 6
  • 26
  • 31