【问题标题】:How to retrieve rows from a specific discriminator in EF 6.1.3?如何从 EF 6.1.3 中的特定鉴别器中检索行?
【发布时间】:2017-04-05 11:18:10
【问题描述】:

我在代码优先模型中使用 TPH 方法,基类是 WItem 类型,派生是 BItem,我只想检索所有 WItems 行,所以我做了这个

return View(db.WItems.OfType<WItem>().ToList());

但我仍然得到所有行WHERE [Extent1].[Discriminator] IN (N'BItem',N'WItem')}

【问题讨论】:

    标签: c# entity-framework ef-code-first entity-framework-6 tph


    【解决方案1】:

    Quora 的一位同事建议这样做:

    db.WItems.Where(s => !(s is BItem));
    

    效果如我所愿。

    【讨论】:

      猜你喜欢
      • 2015-11-04
      • 2012-09-11
      • 2013-03-18
      • 2017-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多