Is there anyone here with experience writing custom Linq proviers?
What I'm trying to do is tell whether a MemberExpression that is a property on a business object should be included in the sql, or treated as a constant, because its from a local variable that just happens to be a business object.
So for example, if you have this:
Customer c = LoadCustomerFromDatabase();
var orders = from o in db.Orders() where o.CustomerID == c.CustomerID select o;
At the moment, my query translator will try to execute "SELECT * FROM orders o where o.CustomerID = c.CustomerID
", which of course doesn't work.
What I would like to do is examine the MemberExpression on the "c.CustomerID" and try to work out if its a local variable, or just something that is being used as part of the linq expression.
I have managed to do it as a 2nd pass over the query, looking for fields that SQL Server won't be able to bind, and injecting their values instead, but if possible I'd like to get it all happening at the same time. I tried looking at the expression Type property, and IsAutoClass, but that was just a guess because it contained the word Auto. And it didnt work :)