问题
I have that :
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
}
Is that a way to do that with Query ? Or maybe another way? I need a IQueryable result...
Thanks
回答1:
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
});
Note: this uses 2 roundtrips however
来源:https://stackoverflow.com/questions/9584950/nhibernate-queryt-with-detached-criteria