问题
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.
回答1:
Figured it out. The [NotMapped] attribute should not have been applied to the base class, but only its properties.
来源:https://stackoverflow.com/questions/10511108/derive-entity-class-from-a-notmapped-class-in-entity-framework-4-1-code-first