In ASP.NET I'm using Entity Framework with a code-first approach and I want based on my model to generate the DB table. One of the attributes is Enum value, and it is not showing as a column in the generated table.
So this is my enum:
public enum MyEnum
{
val_one = 1,
val_two = 2,
val_three = 3
}
And this is my model:
public class MyModel
{
public int Id { get; set; }
public string attrString { get; set; }
public double attrDouble { get; set; }
public MyEnum attrEnum { get; set; }
}
So with the code-first approach I'm having generated table with the following columns:
CREATE TABLE [dbo].[MyModel]
(
[Id] INT IDENTITY (1, 1) NOT NULL,
[attrString] NVARCHAR (MAX) NOT NULL,
[attrDouble] FLOAT (53) NOT NULL,
[attrEnum] INT NOT NULL,
CONSTRAINT [PK_dbo.MyModel] PRIMARY KEY CLUSTERED ([Id] ASC)
);
And later when generating forms (controller and views) based on the model, I'm having a forms where attrEnum
param is missing.
So how to proceed in order to have this enum attribute (in format of dropdown list) in the forms (still using code-first approach). I guess there may be needed generation of another DB table that will contains enums, but I'm really not sure how to do that in Entity Framework since I'm beginner in it.