开发者

SQL query generated by LINQ TO SQL statement

开发者 https://www.devze.com 2022-12-08 11:03 出处:网络
How would i know the SQL statement generated by开发者_如何学运维 my Linq to sql query?You could see the SQL statement by using the toString() statement.

How would i know the SQL statement generated by开发者_如何学运维 my Linq to sql query?


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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消