c# - Chaining / building LINQ query with an OR instead of AND -


edited clearer.

if example have iqueryable:

datetime thedate = new datetime(2015, 09, 30);  var query = org in organisations             org.disableorganisation == false &&               org.disablereports == false             select new             {                 organisationid = org.organisationid             }; 

and later in method want add or it, e.g.

// check see if date last day of month. if (thedate.adddays(1).day == 1) {     // following statement introduces , want make or.     query = query.where(x => x.frequency == "m"); } 

this makes query...

var query = org in organisations             org.disableorganisation == false &&               org.disablereports == false &&               org.frequency == "m"             select new             {                 organisationid = org.organisationid             }; 

but want make it...

var query = org in organisations             (org.disableorganisation == false &&               org.disablereports == false) ||               org.frequency == "m"             select new             {                 organisationid = org.organisationid             }; 

how go making or instead of , ?

p.s. cannot use predicatebuilder linqkit has dependency of entityframework (≥ 6.0.2), i'm stuck using ef 4.3.1

solved: d stanley (to honest had used form of solution before, forgot it).

datetime thedate = new datetime(2015, 09, 30); bool isendofmonth = thedate.adddays(1).day == 1;  var query = org in organisations             (org.disableorganisation == false &&               org.disablereports == false) ||               (isendofmonth &&                pr.profiletype == "l" &&                 pr.frequency == "m")             select new             {                 organisationid = org.organisationid             }; 

you can't chaining - you'll have use sort of expression builder, or build in original filter:

var day = thedate.adddays(1).day;  var query = org in organisations             (org.disableorganisation == false &&                    org.disablereports == false) ||                   (day == 1 &&                    org.profiletype == "l" &&                     org.frequency == "m")             select new             {                 organisationid = org.organisationid             }; 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -