c# - Appending .Where(..) to a Linq.IQueryable -


i building linq iqueryable , want add different .where() argument depending on condition. @ runtime appended .where() doesn't seem taken account. done wrong?

var query = context.sessions    .where(s => s.userid.equals(currentuserid))    .where(s => s.closedtime.hasvalue)    .where(s => !s.approvedtime.hasvalue);  if (type == models.environmenttype.a) {    query.where(s => s.bedroomid.hasvalue); } else if (type == models.environmenttype.b) {    query.where(s => s.homeid.hasvalue); } 

thank you!

you need assign returning result query.where creates new query, doesn't change original one.

query = query.where(s => s.bedroomid.hasvalue); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -