QueryOver如何用于筛选特定的类? [英] How can QueryOver be used to filter for a specific class?
本文介绍了QueryOver如何用于筛选特定的类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在像这样动态构建查询:
I am currently dynamically constructing queries like so:
QueryOver<Base, Base> q = QueryOver.Of<Base>();
if (foo != null) q = q.Where(b => b.Foo == foo);
// ...
现在我要过滤的Base
(例如Derived
)有多个映射子类,基本上是这样的:
Now there are multiple mapped subclasses of Base
(e. g. Derived
) which I want to filter on, basically something like:
if (bar) q = q.Where(b => b is Derived); // does not work
或:
if (bar) q = q.Where(b => b.DiscriminatorColumn == 'derived'); // dito
如何最好地(但不是必须)以类型安全的方式实现这一目标?也可以使用LINQ做到这一点吗?
How do I best achieve that, preferably - but not neccessarily - in a type-safe way? Can this be done using LINQ, too?
推荐答案
这不是 直观的方法,但是以下方法应该可以正常工作(QueryOver):
This is not intuitive, but the following should work fine (QueryOver):
if (bar) q = q.Where(b => b.GetType() == typeof(Derived));
我不确定在LINQ-to-NH中执行此操作的方法.
I'm not sure about a way to do this in LINQ-to-NH.
这篇关于QueryOver如何用于筛选特定的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文