I am working on LINQ to SQL translator. It should translate LINQ queries to SQL. I am focused on creating WHERE part of the query. I am traversing LINQ Expression tree and then I get to a problem that I can't get to the value of actual parameter passed to the method that contains LINQ call.
NOTE: I am not using LINQ to SQL, nor Entity Framework, nor NHibernate because I simply can't since VB6 Legacy system is in the game.
So what I am trying to achieve is to call somewhere on high level this:
int? parameterForCall = cmb.SelectedValue;
Then I have a method like this and it is in ExpenseDAL
class that calls BaseDAL<Expense>.GetAll(X)
:
public IList<Expense> GetAll(int? parameterForCall)
{
IList<Expense> expenses = BaseDAL<Expense>.GetAll(t => t.Fixed ==
parameterForCall);
}
GetAll
method has signature like this:
public static IList<T> GetAll(Expression<Func<T, bool>> predicate = null);
Then I am calling GetCondition
method that converts expression to SQL:
private static string GetCondition(Expression predicate = null);
It is a recursive function. In it I get to a situation that I need to get to parameter that I passed to GetAll
expression, named parameterForCall
.
The problem is that I can write this:
dynamic value = (predicate as ConstantExpression);
And in ImmediateWindow I can see that value.Value is written like this:
{FMC.Proxy.Common.BaseDAL.}
parameterForCall: 19
But I can't get to the value 19. And I want it so I can convert it to value to put to SQL string.
Does anyone know how to get to value 19 so I can use it in the code?