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

喜欢而已 提交于 2019-12-07 06:14:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!