Get FieldExpression value in C#

61 Views Asked by At

I'm new to Expressions in C#, and I'm trying to create a transformer from Expression<Func<T,bool>> to a SQL Where clause. I managed to do so when the provided expression looks like this

Expression<Func<Product, bool>> predicate = p => p.Price > 100 && p.Category == "Electronics" && p.PriceTotal >= 200;

In the above example, I can break the expression to Member Expression and Constant Expression and create the equivalent SQL Where clause. Now I'm trying to do the same for this -

public void GetWhereCluase(string categoryName)
{
    Expression<Func<T,bool>> predicate = p => p.Category == categoryName && p.PriceTotal >= 200;
    GetClause(predicate);
}

But this time, the Right side is a FieldExpression and I don't know how I can get the actual value.

I tried compiling the Func<T,bool> but without luck.

0

There are 0 best solutions below