如何查看LINQ生成的SQL语句? [英] How to view LINQ Generated SQL statements?
本文介绍了如何查看LINQ生成的SQL语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用ObjectQuery方法完成?
How is it done using the ObjectQuery method?
推荐答案
这是我使用ObjectQuery方法找到的内容.使用控制台进行测试,您可以执行以下操作:
Here is what I found using ObjectQuery Method. Using console for testing, you can do the following:
按如下所示创建扩展方法,然后调用它.说产品"产品,然后SQL打印为product.ToTraceString.
Create an Extension Method as below, then call it. Say Product product, then SQL prints out as product.ToTraceString.
public static class MyExtensions
{
public static string ToTraceString<T>(this IQueryable<T> t)
{
string sql = "";
ObjectQuery<T> oqt = t as ObjectQuery<T>;
if (oqt != null)
sql = oqt.ToTraceString();
return sql;
}
}
这篇关于如何查看LINQ生成的SQL语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文