Klas Mellbourn
Klas Mellbourn

Reputation: 44417

Missing columns for enums in Entity Framework

I have built up a code-first model using Entity Framework 5. The classes have several enums.

I started out by putting the model classes in a prototype ASP.NET MVC project. I also added the

Database.SetInitializer(new DropCreateDatabaseAlways<dbType>());

command to the global.asax.cs file.

Running the MVC application in Visual Studio produced exactly the database schema I wanted in SQL Server (2008 R2). (with int value columns for the enums)

I then copied the model code to the solution where it will actually be used, which is split into several projects, one which has the EF code, another is the ASP.NET MVC part.

I also added the same Initializer to global.asax.cs

Now when I run the project, I do get the correct tables in the database, but for some strange reason, the enum columns are missing from the tables!

How do I make EF produce the enum columns?

Upvotes: 1

Views: 1089

Answers (1)

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364399

Enum support is dependent on .NET 4.5 so it will only work when the project targets .NET 4.5.

Upvotes: 13

Related Questions