EF Code-First Migration - Ignore Property

I have a simple poco class that has an enum property (it is necessary that I still have the code that first created the enum lookup table). I do not want the migration generator to add this column to the database. Is there an attribute or some other way for the transition code to know to ignore the property?

Example:

public class MyPoco
{
    public int MyPocoId { get; set; }
    public int MyPocoTypeId { get; set; }

    public MyPocoTypeEnum MyPocoTypeEnum
    {
        get { return (MyPocoTypeEnum)MyPocoTypeId; }
        set { MyPocoTypeId = (int)value; }
    }
}
+3
source share
1 answer

You can use NotMappedAttribute

http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.notmappedattribute(v=vs.103).aspx

Or, I prefer to use smooth matching, as it does not clutter up my domain model with data access problems.

modelBuilder.Entity<MyPoco>().Ignore(p => p.MyPocoTypeEnum); 
+8

All Articles