I want to run a LINQ statement on a DBSet
of EntityFramework.
Since I use a different type of objects (Not the type of my entities) in my application, I need to mutate the expression so it will contain EntityFramework objects and not my application objects.
I used the answer in this question to do so: Mutating the expression tree of a predicate to target another type
But I can't find out how to actually use the result...(as a Predicate
or a Func
, etc)
I've seen that there once was a Compile method in Expression, but it's not there any more.
Can somebody explain to me how to do this?
EDIT:
I'd like to use an interface such as this:
public interface ICRUDFacade<T>
{
bool Create(T source);
IEnumerable<T> Read(Predicate<T> exp);
bool Update(T source);
bool Delete(T source);
}
and in the implementation of the EntityFramework facade
convert T
to an object that can be inserted into a DbSet
.
When I run the LINQ expression in the Read
method I will receive Entity objects and then convert them back to T