【发布时间】:2012-01-30 03:01:48
【问题描述】:
假设我有一个非常简单的类结构,更多的是为了方便。
class A{
[Column("someValue")]
public int someValue{get; set;}
}
[Table("tableB")]
class B{
[Column("somethingElse")]
public int somethingElse{get; set;}
public A somethingEncapsulated{get; set;}
}
[Table("tableC")]
class C{
[Column("otherSomething")]
public int otherSomething{get; set;}
public A somethingEncapsulated{get; set;}
}
而数据库结构,无法更改看起来如此
tableB
------
somethingElse int
someValue int
tableC
-----
otherSomething int
someValue int
是否可以在不消除A类的情况下在Entity Framework中表示这种结构?如果有,怎么做?
【问题讨论】:
-
without eliminating class A是什么意思? -
其他替代方法是在类
B和C中继承类A。然后你可以有几个映射选项,如Table per hierarchy、table per type。 vincentlauzon.wordpress.com/2011/04/19/… -
@Jayantha,继承不是我想到的方法。它可能有效,但首先想到的是说“B 是 A”是否恰当。如果 B 已经从另一个类、更合适的类继承怎么办?
标签: .net c#-4.0 entity-framework-4.1 ef-code-first