How would i know the SQL statement generated by my Linq to sql query?
+6
A:
You could see the SQL statement by using the toString() statement.
var customers = from cust in Customers
select cust;
Console.WriteLine(customers.ToString());
or you could do something like this.
DataContext context = new DataContext(...);
StringWriter writer = new StringWriter();
context.Log = writer;
var customers = from cust in Customers
select cust;
Console.WriteLine(writer.ToString());
daxsorbito
2009-10-16 10:09:44
Thanks... this works :)
mcxiand
2009-10-16 10:15:20
Wow, who knew. I've been using LINQ for a couple of years now and never had any idea that Query.ToString would return the SQL command.
Herb Caudill
2010-10-15 13:06:40
+3
A:
Use LINQ to SQL Debugger Visualizer.
Alternatively, you can set dataContext.Log
property to Console.Out
or something and the SQL statement, along with actual parameter values will be written out to that stream.
Mehrdad Afshari
2009-10-16 10:10:43