Say I have a LINQ query:
var query = (from person in ctx.People where person.Name == "John" select person);
ctx
is a context inheriting from System.Data.Entity.DbContext
.
Now how do I get the full SQL query including the parameters? I have tried:
var sql = ((ObjectQuery) query).ToTraceString();
sql = query.String();
context.Database.Log = (s) => sql += s;
The first solution throws an invalid cast exception. The second solution gives me only the query part which references variables that are not included. The third prints the "variables" in a strange format.