Reputation: 7150
Is it possible to get the generated SQL from a compiled linq query?
Upvotes: 7
Views: 3434
Reputation: 599
Thanks jfs, but the link in your option #1 is not good anymore. It is not showing any relevant article. Chris B's link to the MSDN article helped me.
Here is my solution since mine is not a Console application:
TextWriter tw = new StringWriter();
db.Log = tw;
IQueryable<Customer> custQuery =
from cust in db.Customers
where cust.City == "London"
select cust;
string output = tw.ToString();
// output variable has the generate SQL now
Upvotes: 0
Reputation: 16768
You can:
Upvotes: 9
Reputation: 5119
Use LinqPad :
Or alternatively get use sql server profiler to watch the query. I know you used to be able to however over the query variable in debug and it would show you the query it is going to execute but I am not entirely sure if that still works (Definitely not on client side apps)
Upvotes: 2