c# - How to pass a func<> in linq to sql with a join -
i have following issue.
i want pass func parameter can vary in statement.
private ienumerable<user> getuser(int cant, func<user, bool> userfilter, func<client, bool> clientfilter) { return (from dcu in _db.all<user>().where(userfilter) join c in _db.all<client>() on dcu.idclient equals c.idclient temp cli in temp.defaultifempty().where(clientfilter) select new {usuer = dcu, client = cli}). take(cant).select(uc => _usersmapper.map(uc.user, uc.client)).asenumerable(); }
and func should this
public void getusers () { getuser(50, u => u.email.contains("onemail@mail.com"), c=> true); } public void getusersfilterbyclient () { getuser(50, u => true, c=> c.password.contains("mypasssword")); }
you need lambda where
filter
function:
private ienumerable<user> getuser(int cant, func<user, bool> filter) { return (from dcu in _db.all<user>().where(a => filter(a)) join c in _db.all<client>() on dcu.idclient equals c.idclient temp cli in temp.defaultifempty() select new {usuer = dcu, client = cli}). take(cant).select(uc => _usersmapper.map(uc.user, uc.client)).asenumerable(); }
Comments
Post a Comment