Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Code-First Migration - Ignore Property

I have a simple poco class that has an enum property (Needed so that I can still have the code first create the enum lookup table). I don't want the migration generator to add this column to the database. Is there an attribute or some other way to let the migration code 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; }
    }
}
like image 442
Tyrel Van Niekerk Avatar asked Feb 17 '26 00:02

Tyrel Van Niekerk


1 Answers

You can use NotMappedAttribute

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

Or I prefer to use fluent mapping as it doesn't clutter my domain model with data access concerns.

modelBuilder.Entity<MyPoco>().Ignore(p => p.MyPocoTypeEnum); 
like image 108
Chris Foster Avatar answered Feb 19 '26 19:02

Chris Foster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!