How to Expression.Invoke an arbitrary LINQ 2 SQL Query

Posted by Remus Rusanu on Stack Overflow See other posts from Stack Overflow or by Remus Rusanu
Published on 2010-04-14T17:35:04Z Indexed on 2010/04/14 18:53 UTC
Read the original article Hit count: 255

Filed under:
|
|
|

Say I take an arbitrary LINQ2SQL query's Expression, is it possible to invoke it somehow?

MyContext ctx1 = new MyContext("...");
var q = from t in ctx1.table1 where t.id = 1 select t;
Expression qe = q.Expression;
var res = Expression.Invoke(qe); 

This throws ArgumentException "Expression of type System.Linq.IQueryable`1[...]' cannot be invoked".

My ultimate goal is to evaluate the same query on several different data contexts.

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ