问题描述
我有一个查询,我将 byte[]
作为参数传递.我正在尝试从中获取 SQL 查询并在管理工作室中运行该查询以进行调试.如何从中提取 SQL 语句?
I have a query which I am passing byte[]
as a parameter. I am trying to get the SQL query out of it and run that query in management studio to debug. How can I extract the SQL statement from it?
committeeMember =
db.Committee_Member.FirstOrDefault(x => x.Customer_Number == activity.Contact.Number
&& x.Position_Start_Date.Value.Year == activity.EndDate
&& x.Committee_Id == activity.Committee.Id && x.Cancelled != 1);
推荐答案
在调试器中将鼠标悬停在 commiteeMember
变量上 - 它将显示生成的 SQL 查询:
In debugger hover mouse over commiteeMember
variable - it will show generated SQL query:
这是ToString()
为查询返回的内容.您可以通过调用 ToString 手动获取相同生成的 SQL 查询:
This is what ToString()
returns for query. You can get same generated SQL query manually by calling ToString:
string sql = committeeMember.ToString();
这个重写的方法在内部调用 ObjectQuery.ToTraceString()
返回将在数据源上运行的命令.
This overridden method internally calls ObjectQuery.ToTraceString()
which returns commands that will run on data source.
您也可以使用 SQL Profiler 或 Entity Framework Profiler 来查看执行了哪个 SQL 查询.
Also you can use SQL Profiler or Entity Framework Profiler to see which SQL query was executed.
这篇关于从 LINQ 到 SQL 获取 SQL 查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!