3

I've looked for this everywhere and the examples are of converting a column to a scalar or something. I just want to know if following is possible:

  1. Take a table e.g. Request and associated it with a table called RequestStatus, which has 2 columns: Id, Status and has 4 rows with different statuses.

  2. Some how tell EF5 that RequestStatus table should actually generate an enum in c# side so I can do something like: Request.RequestStatus == RequestStatus.New

  3. Every time I compile, it should update the RequestStatus Enum based on the table in the db specified in the connection string.

Is this possible?

Riz
  • 6,486
  • 19
  • 66
  • 106

2 Answers2

2

Based on this blog it is possible:

Entity Framework 5 + Enumerations => What’s not to love?

Marcos Dimitrio
  • 6,651
  • 5
  • 38
  • 62
MeTitus
  • 3,390
  • 2
  • 25
  • 49
  • it doesn't seem to map to a table called "Habitable" It seems he's just generated HabitableEnum type and is mapping a column called Habitable of type int16 to the HabitableEnum type. I've seen examples like this. What I want is to map the enum to an existing table called Habitable. This is quite a realistic scenario, but it seems Microsoft have completely missed the point if there's no way to accomplish this. – Riz Jun 28 '13 at 21:20
  • @Riz Is it not this that you want? http://stackoverflow.com/questions/11595008/enums-ef-5-0-database-first or am I missing something? – MeTitus Jun 28 '13 at 22:16
1

As long as Entity Framework has started supporting Enums from version 5, you could create a T4 Text Template to generate Enums from database lookup tables and map them to the corresponding property of your entity. Here, you can find an example: Entity Framework 5 and Enum support

Alireza Maddah
  • 5,718
  • 2
  • 21
  • 25