mark vanzuela
mark vanzuela

Reputation: 1391

SQL query generated by LINQ TO SQL statement

How would i know the SQL statement generated by my Linq to sql query?

Upvotes: 3

Views: 1662

Answers (3)

Ravi
Ravi

Reputation: 1313

There is a tool to check the query http://www.linqpad.net/

Upvotes: 0

Mehrdad Afshari
Mehrdad Afshari

Reputation: 421998

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.

Upvotes: 3

daxsorbito
daxsorbito

Reputation: 1810

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());

Upvotes: 6

Related Questions