简体   繁体   English

从Entity Framework 4.1 Code First中的NotMapped类派生实体类

[英]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. 我需要从不属于模型的基类派生我的两个Entity类。

[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. 我已经尝试将基类及其所有属性标记为[NotMapped]但是上下文初始化器会抛出一个错误,指出我的派生实体类都没有映射。

Figured it out. 弄清楚了。 The [NotMapped] attribute should not have been applied to the base class, but only its properties. [NotMapped]属性不应该应用于基类,而只应用于其属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM