Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Derive Entity class from a NotMapped class in Entity Framework 4.1 Code First

I need to derive two of my Entity classes from a base class that does not belong to the model.

[NotMapped]
public abstract class BaseClass
{
    [NotMapped]
    public string SomeProperty { get; set; }
}
public partial class Derived1: BaseClass {}
public partial class Derived2: BaseClass {}

I have tried marking the base class and all its properties as [NotMapped] but the context initializer throw an error saying that both my derived entity classes are not mapped.

like image 614
Raheel Khan Avatar asked Oct 07 '22 21:10

Raheel Khan


1 Answers

Figured it out. The [NotMapped] attribute should not have been applied to the base class, but only its properties.

like image 187
Raheel Khan Avatar answered Oct 11 '22 21:10

Raheel Khan