LINQ - Buidling a search query -


i building search query customer search function: have these fields passing function , wonder best way build linq expression. of fields maybe empty string , search should using "contains" instead of searching exact field string

public list<customer> searchcustomer(     string membershipid,      string prefername,      string firstname,      string lastname,      string nric,      string phonenumber,      string email,      datetime dob,      string gender,      string address,      boolean vip,      bool isdeleted) 

you can manage multiple filter parameters in following way:

var result = customercollection.     .where(c => membershipid != null ? c.membershipid.contains(membershipid) : true)     .where(c => prefername != null ? c.prefername.contains(membershipid) : true)      ...      .tolist(); 

i hope idea


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -