Is it possible to create ICriteria/ICriterion from LINQ or HQL?
Posted
by adrin
on Stack Overflow
See other posts from Stack Overflow
or by adrin
Published on 2010-04-27T15:09:20Z
Indexed on
2010/04/27
15:13 UTC
Read the original article
Hit count: 317
I am creating a method that can create filter understood by NHibernate (by filter i mean a set of ICriteria object for example) from my abstract filter object.
public static IEnumerable<ICriterion> ToNhCriteria(this MyCriteria criteria)
{
// T4 generated function
// lots of result.Add(Expression.Or(Expression.Eq(),Expression.Eq)) expression trees - hard to generate
// Is there a way to generate HQL/Linq query here istead?
}
then i want to do something like
session.CreateCriteria<Entity>().Add(myCriteria.ToNhCriteria())
to filter entities. The problem is that using Expression. methods (Expression.Or etc) is quite tedious (the method is generated and i have multiple or statements that have to be joined into an expression somehow). Is there a way to avoid using Expression.Or() and create ICrietrion / ICriteria using LINQ or HQL?
© Stack Overflow or respective owner