1

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

techspider
  • 3,370
  • 13
  • 37
  • 61

1 Answers1

0

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.

mfanto
  • 14,168
  • 6
  • 51
  • 61
  • looks like I can't use it as enum any more. I see my data has Guid instead of an auto-increment number in DB. need to find another way as I can't create enum which expects int always :( – techspider Mar 16 '15 at 20:59
  • 2
    @techspider: Hi fellow dev. I'm the original author of the T4 script for lookup tables. In your case I would suggest to adjust the T$ script to generate static class with string/GUID properties and assign them your GUIDs. This would make it possible for you to use this class similar to Enum type, but with more flexibility about its values. – Robert Koritnik Nov 03 '16 at 23:42
  • thanks @RobertKoritnik for your suggestion. I'll try to check the route next time I come across – techspider Nov 07 '16 at 22:21