c# - Building a lambda expression using concatenation -


let's have these 2 entities :

  • document, contains datetime property (called date).
  • period, contains 2 datetime properties (called datefrom , dateto) represents period of time.

then, consider expression, in d represents document , p represents period, used filter document collection return part of given period :

d => d.date >= p.datefrom && d.date <= p.dateto 

the problem is, given collection of period entities, how build lambda expression represents concatenation of multiple expressions above expression, gives :

d =>       (d.date >= p1.datefrom && d.date <= p1.dateto)    && (d.date >= p2.datefrom && d.date <= p2.dateto)    && (d.date >= p3.datefrom && d.date <= p3.dateto)    && ... 

i want result lambda expression can further combine other conditions before filtering document collection.

var documentsinallperiods = documents.where(d => periods.all(p =>      d.date >= p.datefrom && d.date <= p.dateto)); 

(note can change all any if want documents in period rather documents in every period.)


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -