How to Expression.Invoke an arbitrary LINQ 2 SQL Query?

Queries are not Expressions. A Query has an ExpressionTree Queries are not Methods to be invoked Queries may be Enumerated, yielding their results. This code will Enumerate any IQueryable: List result = query.Cast().ToList() My ultimate goal is to evaluate the same query on several different data contexts Then you should write your queries as query generators, that accept DataContext as a parameter Func> queryGen = (dc) => dc.Customers.

Where(c => c. Name == "Bob"); //now we can get some queries IQueryable query1 = queryGen(new MyDataContext()); IQueryable query2 = queryGen(new MyDataContext()).

Queries are not Expressions. A Query has an ExpressionTree. Queries are not Methods to be invoked.

Queries may be Enumerated, yielding their results. This code will Enumerate any IQueryable: List result = query.Cast().ToList(); My ultimate goal is to evaluate the same query on several different data contexts. Then you should write your queries as query generators, that accept DataContext as a parameter.

Func> queryGen = (dc) => dc.Customers. Where(c => c. Name == "Bob"); //now we can get some queries IQueryable query1 = queryGen(new MyDataContext()); IQueryable query2 = queryGen(new MyDataContext()).

Are you claiming the property IQueryable. Expression does not exists? Msdn.microsoft.Com/en-us/library/… – Remus Rusanu Apr 14 '10 at 18:30 Accessing a query's Expression in order to tamper with the DataContext is like disassembling your car engine in order to turn on the radio.

– David B Apr 14 '10 at 18:52.

LINQ2SQL expressions are parsed by the LINQ2QL Provider and converted into T-SQL. My guess is that exception is being raised explicitly- that Microsoft did not intend for those expressions to be Invoked directly (you could confirm this using Reflector. ).

If you goal is to run an Expression across different contexts, why not create just the expression like so:- Expression> myExpression = x => x. Id == 1; Then you can do whatever you like with it, including using it in .Where() clauses.

A query is way more than a WHERE clause. I want arbitrary queries. – Remus Rusanu Apr 14 '10 at 18:03.

Queries are not Expressions. A Query has an ExpressionTree. Queries are not Methods to be invoked.

Queries may be Enumerated, yielding their results. Then you should write your queries as query generators, that accept DataContext as a parameter.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions