简体   繁体   中英

Generate Enum from Lookup Tables - EF 6

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

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 (ie that the id's are named TableNameID ). Then add in the appropriate .tt files for each Enum, and run the template.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM