Let’s say i had two parameters:
parameter 1 an expression that takes a T and fetches the associated product’s ID from it
Expression<Func<T,int>> prodIdProperty = x=>x.Product.Id
parameter 2 a productid to compare with , let’s say
int productid = 5;
Is there any way I could runtime transform this (in code) into a new expression like this:
Expression<Func<T,bool>> prodIdProperty = x=>x.Product.Id == 5
I basically need something like this:
Expression<Func<T,bool>> TransformToPredicate(Expression<Func<T,int>> prodIdProperty,int productid){
//insert expression transform magic I don't seem to grasp...
}
I need this because I want to pass it as a predicate to my EF Where clause, that means I cannot included Compiled versions of my prodIdProperty as It requires calling Invoke() wich is not supported
(I already tried formulating my problem another way in this question, but I think I overcomplicated it there)
It sounds like you want something like:
Sample code showing it in action: