调试Linq to sql代码是, 如果遇到错误,很难判断错误的原因是什么,如果能够输出实际执行的sql原文,对于我们寻找错误的原因有有很大帮助。

 

以下是我用到的方法:

       

       StringBuilder sql = new StringBuilder();
          try
          {
              using (var context = new DataContext())
              {
                  context.Log = new System.IO.StringWriter(sql);
                  context.SubmitChanges();
              }
          }
          finally
          {
              sql.ToString();
          }

 

相关文章:

  • 2021-12-18
  • 2021-07-09
  • 2021-10-16
  • 2022-02-24
猜你喜欢
  • 2021-08-16
  • 2021-09-15
  • 2021-05-16
  • 2022-12-23
相关资源
相似解决方案