Extract sql query from LINQ expressions

后端 未结 5 1567
太阳男子
太阳男子 2020-12-15 22:06

Is it possible to extract sql statements from LINQ queries ?

Say, I have this LINQ expression.

        string[] names =
            ne         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-15 22:26

    For future reference, I think this gentleman's method is the best http://damieng.com/blog/2008/07/30/linq-to-sql-log-to-debug-window-file-memory-or-multiple-writers

    class DebugTextWriter : System.IO.TextWriter {
       public override void Write(char[] buffer, int index, int count) {
           System.Diagnostics.Debug.Write(new String(buffer, index, count));
       }
    
       public override void Write(string value) {
           System.Diagnostics.Debug.Write(value);
       }
    
       public override Encoding Encoding {
           get { return System.Text.Encoding.Default; }
       }
    }
    
    myDataContext.Log = new DebugTextWriter();
    

提交回复
热议问题