I have extension method that has the following signature:
public static class GenericSeeder
{
public static void Seed<TSeed, TEntity>(this DbContext context, IEnumerable<TSeed> seeds, Expression<Func<TEntity, TSeed, bool>> predicate)
{
// code that I'm looking for goes here
}
}
To have better understanding of what the method is doing, here's how it should be used:
context.Seed<SeedClass, EntityClass>(seeds, (entity, seed) => entity.Name == seed.OtherProperty);
So basically, I am using the predicate to check whether the seed was already applied. However, in order to do a check, I must use Where or FirstOrDefault from Linq to Entities, which takes the following as parameter:
Expression<Func<TEntity, bool>> predicate
So my lambda expression is function of 2 IN parameters (TSeed, TEntity) and 1 OUT parameter (bool). I need to iterate through provided collection of TSeed objects, and for each of those, use that object as parameter for my lambda expression, to generate LINQ 2 Entities lambda expression which has 1 IN parameter (TEntity) and 1 OUT parameter (bool).
Is there a way to do a partial invoke of lambda expression / func to get another lambda expression / func?
(x,y)=>{x.Frob();return y==x;}
or something like that (compiled fine in my head, may not with a real compiler). This would allow you to internally do stuff with only one property and then the other. I can't guarantee that any linq provider apart from linq to objects will be able to do things with that (and indeed would expect probably not).==
?