Is it possible to create ICriteria / ICriterion from LINQ or HQL?
I am creating a method that can create a filter that NHibernate understands (for example, by filter I mean a set of ICriteria objects) 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 objects. The problem is that using the expression. the methods (Expression.Or, etc.) are quite tedious (the method is generated and I have several or operators that must somehow be combined into an expression). Is there a way to avoid using Expression.Or () and create an ICrietrion / ICriteria using LINQ or HQL?
a source to share
Linq is not the best solution unless you want to do filtering on the collection side rather than the database side using WHERE clauses. Ayende suggests that the ICriteria API is good for making a dynamic filter, the problem I faced with multiple ORs was solved with Restrictions.Disjunction () ... which simplified a lot At the time I asked the question, I just didn't understand that such things exist in NHibernate :)
a source to share