The basis of the problem is that I have Ids stored in these two expressions and I need to search an array for their objects with these Ids so I can compare these two expressions based on Text.
I have this code
Expression firstExpression; //it has a value which is dynamically set during runtime
Expression secondExpression; //it has a value which is dynamically set during runtime
BinaryExpression operator = BinaryExpression.Equal;
Enumerable items = [{Id: 1, Text: "hello"}, {Id: 2, Text: "hello"}] // array of objects with ids and texts
I tried these combinations and they didnt return correctly.
var item = items.SingleOrDefault(x => firstExpression == Constant.Expression(x).Value);
// resulting sql looks something like this SingleOrDefault(x => item.Variable == x.Value);
var item = items.SingleOrDefault(x => Constant.Expression(firstExpression) == Constant.Expression(x).Value);
var item = items.SingleOrDefault(x => Constant.Expression(firstExpression).Value == Constant.Expression(x).Value);
The end result should look something like:
Expression.MakeBinary(operator, Expression.Constant(item), Expression.Constant(secondItem))
I also tried compiling and invoking the expression then I just received an error that a variable is out of scope,
firstExpression.Compile().DynamicInvoke();
Because the expression variable is dynamic i dont think i can compile it but Im not sure
if you have any idea how would you retrieve this value, or maybe do this somehow differently.