asp.net mvc - How to Map Enum Values to a Lookup Table - Code First -


i'm using code first , migration update db. have lookup table , correspond enum. table: states

id | state ---|-------    | 

my enum:

public enum states     {         = 1,         bad = 2     } 

i want fill state table values of enum, if change enum values - table changed in accordance. googled lot couldn't find clear it.

any basic example appreciated.

a google turns ef-enum-to-lookup project, looks want.

creates lookup tables , foreign key constraints based on enums used in model.

install nuget...

install-package ef-enum-to-lookup 

you can run with...

var enumtolookup = new enumtolookup(); enumtolookup.apply(context); 

you run migrations seed method, you'll need aware adding enum member not change model, if you're using explicit migrations seed method won't run.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -