Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL query generated by LINQ TO SQL statement

Tags:

linq-to-sql

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

like image 855
mark vanzuela Avatar asked Dec 18 '25 00:12

mark vanzuela


1 Answers

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());
like image 176
daxsorbito Avatar answered Dec 20 '25 06:12

daxsorbito



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!