【问题标题】:Using inheritance in Entity Framework?在实体框架中使用继承?
【发布时间】:2011-03-15 09:10:07
【问题描述】:

我在 DB 中有两个表:Foo 和 Bar

使用实体框架我想创建包含两个表都具有的属性的基本实体。

例如 Foo 有列 Id,CreateDate,FooValue 并且 Bar 有 Id,CreateDate,BarValue

  • 所以 BaseEntity 应该有 Id 和 CreateDate 属性
  • Foo 应该继承 BaseEntity 并具有 FooValue
  • Bar 应该继承 BaseEntity 并具有 BarValue

如何将属性映射到它们在 DB 中的表?

【问题讨论】:

    标签: entity-framework inheritance


    【解决方案1】:

    我假设你想要Table per Concrete Type (TPC) - 这里是blog post with a walkthrough。也可以考虑修改表并使用每个类型的表 (TPT),但我认为这对于像 CreationDate 这样的列来说是一个糟糕的决定,因为您将获得一个包含所有表的创建日期的表。

    【讨论】:

      猜你喜欢
      • 2011-05-19
      • 2010-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-08
      相关资源
      最近更新 更多