如何从EF 6.1.3中的特定标识符检索行? [英] How to retrieve rows from a specific discriminator in EF 6.1.3?

查看:119
本文介绍了如何从EF 6.1.3中的特定标识符检索行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

但是我仍然会收到所有行 WHERE [Extent1]。[Discriminator] IN(N'BItem',N'WItem')}

解决方案

建议:

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

正如我所希望的那样工作。


I'm using TPH approach in my code-first model, the base class is of type WItem and the derived is BItem, I want to retrieve all the WItems rows only, so I made this

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

but I still get all the rows WHERE [Extent1].[Discriminator] IN (N'BItem',N'WItem')}?

解决方案

A fellow from Quora suggested this:

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

It works as I hoped.

这篇关于如何从EF 6.1.3中的特定标识符检索行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆