SQL query generated by LINQ TO SQL statement

How can I recognize the SQL statement generated by my Linq to sql query?

+3
source share
3 answers

You can see the SQL statement using the toString () statement.

var customers = from cust in Customers
        select cust;

Console.WriteLine(customers.ToString());

or you can 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());
+6
source

Use LINQ to SQL Debugger Visualizer .

Alternatively, you can set the property to a dataContext.Logvalue Console.Outor something similar, and the SQL statement, as well as the actual parameter values, will be written to this stream.

+3
source

Source: https://habr.com/ru/post/1720265/


All Articles