c# - Lambda Expression with two IN parameters to Lambda Expression with single IN parameter -
i have extension method has next signature:
public static class genericseeder { public static void seed<tseed, tentity>(this dbcontext context, ienumerable<tseed> seeds, expression<func<tentity, tseed, bool>> predicate) { // code i'm looking goes here } } to have improve understanding of method doing, here's how should used:
context.seed<seedclass, entityclass>(seeds, (entity, seed) => entity.name == seed.otherproperty); so basically, using predicate check whether seed applied. however, in order check, must utilize or firstordefault linq entities, takes next parameter:
expression<func<tentity, bool>> predicate so lambda look function of 2 in parameters (tseed, tentity) , 1 out parameter (bool). need iterate through provided collection of tseed objects, , each of those, utilize object parameter lambda expression, generate linq 2 entities lambda look has 1 in parameter (tentity) , 1 out parameter (bool).
is there way partial invoke of lambda look / func lambda look / func?
through utilize of linqkit allow expressions invoked in such way transformed other expressions implementation of method becomes trivial:
public static iqueryable<tentity> seed<tseed, tentity>( dbcontext context, ienumerable<tseed> seeds, expression<func<tentity, tseed, bool>> predicate) { homecoming context.set<tentity>() .asexpandable() .where(entity => seeds.any(seed => predicate.invoke(entity, seed))); } c# linq generics lambda
No comments:
Post a Comment