Inheritance EF 5具有不同键名的派生类
我在EF数据库中首先遇到以下情况:Inheritance EF 5具有不同键名的派生类,inheritance,frameworks,entity,Inheritance,Frameworks,Entity,我在EF数据库中首先遇到以下情况: public class BaseClass { [Key] public int Id {get;set;} /* other properties */ } public class DerivedClass : BaseClass { [NotMapped] public int Id {get;set;} [Key]
public class BaseClass
{
[Key]
public int Id {get;set;}
/* other properties */
}
public class DerivedClass : BaseClass
{
[NotMapped]
public int Id {get;set;}
[Key]
public int DerivedId {get;set;}
/* other properties */
}
此时,上面的代码不起作用,因为我试图取消映射Id属性,将DerivedId声明为密钥。有解决办法吗?我知道最好的解决方案是在数据库中将DerivedId列重命名为Id,但我不能这样做,因为数据库已经存在于第三方,无法修改
如果我没有错的话,EF4.x中缺少这种方法,我发布这篇文章,希望它是在5.0版的.NET4.5中实现的
谢谢,
Lixi能否创建一个引用基类中Id的新属性
[NotMapped]
public int DerivedId
{
get { return Id; }
set { Id = value; }
}