NHibernate Query <T> with separate criteria ...

I have:

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 this the way to do it with Query? Or maybe another way? I need an IQueryable result ...



source to share

1 answer

linq vendor does not use criteria under the covers, it uses AST from HQL parser. If you really want an IQueryable then you can formulate a query like this

var ids = session.QueryOver<MyClass>()
    .UnderlyingCriteria.Add(SpatialExpression.Within("Geo", extent))
    .Select(myclass => myclass.Id)

var query = session.Query<MyClass>()
    .Where(x => ids.Contains(x.Id))
    .Select(item => new MyClassView
        Name, Year, Code


Note: This uses 2 rounds, but



All Articles