Generate Enum from Lookup Tables - EF 6

c# database-first ef-database-first entity-framework entity-framework-6

Question

This might sound repeated but I have gone through all the available posts but could not figure out the best method in EF 6 version.

I have two tables

PersonPhone (PersonID, PhoneTypeID)

PhoneType(PhoneTypeID, Description)

PhoneTypes as just look ups (Cell, Office, Pager etc). How do I generate equivalent Enums in code from PhoneType table.

Can anyone please provide steps to generate ENums from Look up tables? Thanks in advance

1
0
3/16/2015 7:15:53 PM

Accepted Answer

One way is with a T4 Template that will automatically generate your Enum's from the table.

Here is a great template that I've used in a couple projects. Just change the connection string, and make sure the scripts assumptions about the format of your data are correct (i.e. that the id's are named TableNameID). Then add in the appropriate .tt files for each Enum, and run the template.

0
3/16/2015 7:22:15 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow