LINQ TO SQL语句生成的SQL查询

mar*_*ela 3 linq-to-sql

我怎么知道我的Linq生成的SQL语句到SQL查询?

dax*_*ito 6

您可以使用toString()语句查看SQL语句.

var customers = from cust in Customers
        select cust;

Console.WriteLine(customers.ToString());
Run Code Online (Sandbox Code Playgroud)

或者你可以做这样的事情.

DataContext context = new DataContext(...);
StringWriter writer = new StringWriter();
context.Log = writer;

var customers = from cust in Customers
        select cust;

Console.WriteLine(writer.ToString());
Run Code Online (Sandbox Code Playgroud)