SQL query generated by LINQ TO SQL statement

后端 未结 3 1406
南旧
南旧 2021-01-14 18:41

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

相关标签:
3条回答
  • 2021-01-14 18:54

    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());
    
    0 讨论(0)
  • 2021-01-14 18:57

    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.

    0 讨论(0)
  • 2021-01-14 19:11

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

    0 讨论(0)
提交回复
热议问题