Many problems today! I can't figure this out so I thought I'd throw it out there.
I am writing a fluent interface to build an SQL string (yes I know about LINQ to Entities...it's a long story).
I am checking the type of expression in an if/else clause, like this:
if (expression is MemberExpression)
{
var memberExpression = expression as MemberExpression;
StringBuilder sb = new StringBuilder();
...
return sb.ToString();
}
if (expression is MethodCallExpression)
{
var methodCallExpression = expression as MethodCallExpression;
return GetParameterString(Expression.Lambda(expression).Compile().DynamicInvoke().ToString());
}
if (expression is ConstantExpression)
{
var constantExpression = expression as ConstantExpression;
return GetParameterString(constantExpression.Value.ToString());
}
When I run the following through this code:
.Where(j => j.Driver.Chatiness == searchResource.Chatiness)
...the "searchResource.Chatiness" is activating the MemberExpression code, when ought to be acivating the ConstantExpression (since searchResource is an object containing a Chatiness property).
Why is this? I've got a few ideas of how I can work around it, but I don't want to work around it, I want it to work!