c# - Creating dynamic Linq query based on property values -


i have class contains number of properties of type bool.

public class filtermodel  {     public bool hotel { get; set; }     public bool apartment { get; set; }     public bool guesthouse { get; set; }  } 

i constructing linq query dynamically based on whether or not these properties true or false. example if had instance of class , hotel set true. want generate linq query like

var q = accom in db.accommodation                      accom.hotel == true                       select accom; 

thanks in advance

are looking this?

iqueryable<accommodation> query = db.accommodation;  if (filtermodel.hotel)      query = query.where(a => a.hotel); if (filtermodel.apartment)  query = query.where(a => a.apartment); if (filtermodel.guesthouse) query = query.where(a => a.guesthouse);  return query; 

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -