I think your scenario better suits using the Criteria API, rather than Linq.
On Tue, Aug 11, 2009 at 4:12 PM, lukefrice <[email protected]> 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 Aug 11, 9:14 am, lukefrice <[email protected]> wrote: > > Basically I am doing it like this. > > > > private static Expression<Func<Student, bool>> ProcessCriteria > > (SearchCriteria.StringValue criteria) > > { > > if (criteria.FieldName == "FirstName") { return > > BuildFirstName(criteria.Value, criteria.Comparer); } > > } > > > > private static Expression<Func< Student, bool>> BuildFirstName(string > > value, StringFilterType comparer) > > { > > switch (comparer) > > { > > case StringFilterType.Contains: > > return (s) => s.FirstName.Contains(value); > > case StringFilterType.EndsWith: > > return (s) => s.FirstName.EndsWith(value); > > case StringFilterType.Equals: > > return (s) => s.FirstName == value; > > default: > > return (s) => s.FirstName.StartsWith(value); > > } > > } > > > > This way when i call into the class containing this, i can pass in > > just the field name and the comparer type and it knows which set of > > comparers. > > After this I am combining the Expressions together with this inside my > > dataProvider. > > > > var query = _session.Linq<Student>().AsQueryable(); > > query = StudentSearchCriteriaManager.BuildQuery(query, > > criteria); > > return query.ToList(); > > > > and here is part of the BuildQuery method used to put them together > > > > result = result.Where(ProcessCriteria((SearchCriteria.NumericValue) > > item)); > > break; > > > > On Aug 10, 5:09 pm, John Rayner <[email protected]> wrote: > > > > > > > > > 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 <[email protected]> wrote: > > > > > > I do understand, but I am looking more for something like > > > > PredicateBuilder. Is there anything like that that can be used with > > > > NHibernate? > > > > > > On Aug 10, 1:23 pm, Tuna Toksoz <[email protected]> wrote: > > > > > > > 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://devlicio.us/blogs/tuna_toksozhttp://tunatoksoz.comhttp://twitt... > > > > > > > On Mon, Aug 10, 2009 at 9:20 PM, lukefrice <[email protected]> > wrote: > > > > > > way to combine some of them as OR's, or po- Hide quoted text - > > > > > > - Show quoted text - > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
