我想在使用EF 4.x时实现Layer Supertype模式((PoEAA)。
假设我有一个名为Entity的图层超类型类,教师和学生继承了两个类。
类Person定义如下
class Entity
{
public int Id {get;set;}
}
老师和学生都喜欢这个
class Teacher : Entity
{
publix string Name {get;set;}
}
class Student : Entity
{
public int Age {get;set;}
}
如何配置EF 4.x,以便在我的数据库中,我只有两个与教师和学生相对应的表格?我尝试使用TPC继承策略来映射这个结构,但它不适合,它为每个具体类创建一个表一个..
使用NHibernate,这种情况很常见并且处理得很好,我的意思是如果我只为Person和Student创建映射,数据库将只有两个表,我不必显式实现任何继承startegy。 / p>
感谢您的所有建议
Riana
答案 0 :(得分:0)
使Entity
类抽象
public abstract class Entity
{
public int Id {get;set;}
}
public class Teacher : Entity
{
publix string Name {get;set;}
}
public class Student : Entity
{
public int Age {get;set;}
}