【发布时间】:2012-08-13 18:59:15
【问题描述】:
为复杂实体定义导航属性的官方方法是:
public class SuperEntity
{
public int Id { get; set; }
//Other properties
}
public class LowerEntity
{
public int Id { get; set; }
public int SuperEntityId { get; set; }
public virtual SuperEntity SuperEntity { get; set; }
//Other properties
}
这里的主要内容是引用的类(允许导航到链接的超级实体)既有public SuperEntity SuperEntity { get; set; } 属性,也有public int SuperEntityId { get; set; } 中的Id。
我在实体设计中花了几天时间在“下层实体”中省略了 public int SuperEntityId { get; set; } 属性。所以我只通过虚拟 SuperEntity 属性导航。一切正常!但是我有人告诉我它在数据库中创建了一个过多的表。我查过了,这不是真的。当我使用我的方法时,数据库表具有 SuperEntityId 列,并自动使用引用的实体 ID 填充它。那么这个public int SuperEntityId { get; set; } 字段有什么意义呢?
或者,也许,我正在做的事情在 4.3 等“新”版本的 EF 中可用?
【问题讨论】:
标签: entity-framework