Nhibernate.Linq: Limiting query results using Where (Expression <Predicate <T>>)

I am querying my database using NHibernate. Now I need to limit the data selection with Predicate. So far I have figured out (at the heart of my Google development) that something like this is possible with Expressions and NHibernate.Linq.

Here is what I tried:

public IList<Bestellung> GetAll(Predicate<Order> predicate)
{
    Expression<Func<Order, bool>> restriction = x => predicate(x);
    ISession session = SessionService.GetSession();
    IList<Order> bestellungen = session.Query<Order>()
                        .Where(restriction).ToList();
    return bestellungen;
}

The result is Unable to pass an object of type "NHibernate.Hql.Ast.HqlCast" to enter "NHibernate.Hql.Ast.HqlBooleanExpression" . Just a quickie to check where it sucks: change the first line of the method body to

Expression<Func<Order, bool>> restriction = x => x.Id!=1;

with an amazing result that everything is working fine.

How can I get my predicate in an expression?

+5
1

- . NHibernate ( EF LINQ to SQL) SQL. NHibernate , SQL.

Predicate<T> Expression<Func<T, bool>>:

public IList<Bestellung> GetAll(Expression<Func<Order, bool>> restriction)
{
    ISession session = SessionService.GetSession();
    IList<Order> bestellungen = session.Query<Order>()
                        .Where(restriction).ToList();
    return bestellungen;
}

:
, , - , :

var orders = GetAll(x => x.Id != 1);
+5

All Articles