[nhusers] Re: Dynamic OR's in NHibernate

2009-08-11 Thread Bill Barry
Depending on how sophisticated the NHLinq implementation is, you may need to run an expression visitor which visits the expression tree and simplifies all of the method calls. You can get such a project here: http://tomasp.net/blog/linq-expand.aspx Bill Barry wrote: > private static Expression>

[nhusers] Re: Dynamic OR's in NHibernate

2009-08-11 Thread Bill Barry
private static Expression> ProcessCriterias(List clist) { return clist.Select(item => ProcessCriteria(item)).Aggregate(Or); } private static Expression> Or(Expression> expr1, Expression> expr2) { var invokedExpr = Expression.Invoke(expr2, e

[nhusers] Re: Dynamic OR's in NHibernate

2009-08-11 Thread James Gregory
I think your scenario better suits using the Criteria API, rather than Linq. On Tue, Aug 11, 2009 at 4:12 PM, lukefrice wrote: > > So most simply, it would be best if there were a way to dynamically > add OR's into the lambda expression. As far as i know, though, thats > not an option. > > On Au

[nhusers] Re: Dynamic OR's in NHibernate

2009-08-11 Thread lukefrice
So most simply, it would be best if there were a way to dynamically add OR's into the lambda expression. As far as i know, though, thats not an option. On Aug 11, 9:14 am, lukefrice wrote: > Basically I am doing it like this. > > private static Expression> ProcessCriteria > (SearchCriteria.Strin

[nhusers] Re: Dynamic OR's in NHibernate

2009-08-11 Thread lukefrice
Basically I am doing it like this. private static Expression> ProcessCriteria (SearchCriteria.StringValue criteria) { if (criteria.FieldName == "FirstName") { return BuildFirstName(criteria.Value, criteria.Comparer); } } private static Expression> BuildFirstName(strin

[nhusers] Re: Dynamic OR's in NHibernate

2009-08-10 Thread John Rayner
Create your own Disjunction object? Disjunction disj = new Disjunction(); for(int i = 0; i < numRestrictions; i++) disj.Add( Restrictions.Eq( ) ); If not this, then please give an example of the sort of code you'd like to write. Cheers, John On Aug 10, 8:15 pm, lukefrice wrote: >

[nhusers] Re: Dynamic OR's in NHibernate

2009-08-10 Thread Tuna Toksoz
this is programatic, you have as much flexibility as your imagination. ICriterion x=something; if(something) x=Restrictions.Or(x,anotherRestriction); if(another) x=Restrictions.Or(x,anotherthinghere); Can I tell what I mean? Tuna Toksöz Eternal sunshine of the open source mind. http://de

[nhusers] Re: Dynamic OR's in NHibernate

2009-08-10 Thread lukefrice
Well i see that Or's can be applied, but I need them to be added dynamically, so if they want to select 28 states, then it has 28 or's added. I am using a method which is passing in all the criteria i need and then it returns them as an IQueryable and then it sends the whole query into NHibernate.

[nhusers] Re: Dynamic OR's in NHibernate

2009-08-10 Thread Tuna Toksoz
https://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/querycriteria.html Look for or. Tuna Toksöz Eternal sunshine of the open source mind. http://devlicio.us/blogs/tuna_toksoz http://tunatoksoz.

[nhusers] Re: Dynamic OR's in NHibernate

2009-08-10 Thread lukefrice
Yes. Is there a way to do that? On Aug 10, 11:46 am, Tuna Toksoz wrote: > Criteria with disjunctions? > > Tuna Toksöz > Eternal sunshine of the open source mind. > > http://devlicio.us/blogs/tuna_toksozhttp://tunatoksoz.comhttp://twitter.com/tehlike > > > > On Mon, Aug 10, 2009 at 7:43 PM, lukef

[nhusers] Re: Dynamic OR's in NHibernate

2009-08-10 Thread Tuna Toksoz
Criteria with disjunctions? Tuna Toksöz Eternal sunshine of the open source mind. http://devlicio.us/blogs/tuna_toksoz http://tunatoksoz.com http://twitter.com/tehlike On Mon, Aug 10, 2009 at 7:43 PM, lukefrice wrote: > states, and they --~--~-~--~~~---~--~~