The following query causes an exception on execution. Example uses the NorthwindEF sample database, db is the ObjectContext
num = 10000;
var q = db.Orders.Where(o => o.OrderID > num);
var result = db.Customers.Where(c => q.Any(o => o.CustomerID == c.CustomerID)).ToList();
I'm getting the following exception:
An exception occured during the execution of 'Extent<Customers>().Where(c => value(<>c__DisplayClass2).q.Any(o => (o.CustomerID == c.CustomerID)))'.
Failure: Query parameter name is not declared.
Parameter name: expression
Actual value: value(<>c__DisplayClass2).num.
If I use the actual constant value instead of the num variable, the query works, however in my scenario I'm unable to make any assumption about how q came to be except that it's an IQueryable<T> created over the same object context (db).