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
Post a Comment