【发布时间】:2016-04-26 13:11:18
【问题描述】:
我正在开发一个 asp.net mvc web 应用程序。我已经使用 EF-6 映射了我的数据库表,它创建了一个包含我的模型类的 .tt 文件夹。但我注意到实体框架没有定义模型类之间的继承,而是使用类之间的引用。例如,我有一个父数据库表名 Technology,它有子表,例如 Server 、 VM 等。 现在为技术和服务器生成的类如下所示:-
public partial class Technology
{
public Technology()
{
this.Servers = new HashSet<Server>();
}
public int TechnologyID { get; set; }
public string Tag { get; set; }
public bool IsDeleted { get; set; }
public byte[] timestamp { get; set; }
public Nullable<int> TypeID { get; set; }
public Nullable<long> PartialTag { get; set; }
public bool IsManaged { get; set; }
public virtual Server Server { get; set; }
public virtual VirtualMachine VirtualMachine { get; set; }
}
public Server()
public int ServerID { get; set; }
public int ServerModelID { get; set; }
public string ILOIP { get; set; }
public Nullable<int> RackID { get; set; }
public Nullable<int> StatusID { get; set; }
public Nullable<int> BackUpStatusID { get; set; }
public int RoleID { get; set; }
public Nullable<int> OperatingSystemID { get; set; }
public Nullable<int> VirtualCenterID { get; set; }
public string Comment { get; set; }
public byte[] timestamp { get; set; }
public virtual Technology Technology { get; set; }
}
在 DB 内部,Server.ServerID 是 Technology.TechnologyID 的外键。
所以我期待 EF 将 Technology 定义为父对象,并且 Server、VM 将扩展(继承技术)。但是 EF 会在其子项中为技术创建一个引用.. 那么使用这种方法而不是创建继承的想法是什么?
【问题讨论】:
标签: c# entity-framework inheritance object-oriented-analysis