NHibernate查询与独立的标准... [英] NHibernate Query<T> with detached criteria...
本文介绍了NHibernate查询与独立的标准...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有:
var query = session.Query<MyClass>();
// Here I need to execute a detached criteria, like that :
// query.UnderlyingCriteria.Add(SpatialExpression.Within("Geo", extent));
var t = query.Select(item => new MyClassView
{
Name, Year, Code
}
这是使用Query做到这一点的方法吗?或者也许是另一种方式?我需要一个IQueryable结果...
Is that a way to do that with Query ? Or maybe another way? I need a IQueryable result...
谢谢
推荐答案
linq提供程序在幕后不使用Criteria,而是使用HQL解析器中的AST.如果您确实需要IQueryable,则可以制定这样的查询
the linq provider does not use Criteria under the covers, it uses the AST from the HQL parser. If you really need an IQueryable then you could formulate a query like this
var ids = session.QueryOver<MyClass>()
.UnderlyingCriteria.Add(SpatialExpression.Within("Geo", extent))
.Select(myclass => myclass.Id)
.List<int>();
var query = session.Query<MyClass>()
.Where(x => ids.Contains(x.Id))
.Select(item => new MyClassView
{
Name, Year, Code
});
注意:但是,这需要2次往返行程
Note: this uses 2 roundtrips however
这篇关于NHibernate查询与独立的标准...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文