公开 LINQ 执行时触发的 SQL
大家早上好。
为您简单介绍一下 - 在哪里可以找到 LINQ 语句触发时执行的 SQL?
我有以下代码,可以正常工作,
var r = (from p in getproductweightsbuyer.tblWeights
where p.MemberId == memberid &&
p.LocationId == locationid
select p);
if (buyer != "Not Specified")
r = r.Where(p => p.UnitUserField1 == buyer);
if (subcategory != "Not Specified")
r = r.Where(p => p.UnitUserField2 == subcategory);
我只是不确定在条件 where 子句中触发的 SQL。
Morning all.
Just a quick one for you - where can I find the SQL that is executed when a LINQ statement fires?
I have the following code that works a treat,
var r = (from p in getproductweightsbuyer.tblWeights
where p.MemberId == memberid &&
p.LocationId == locationid
select p);
if (buyer != "Not Specified")
r = r.Where(p => p.UnitUserField1 == buyer);
if (subcategory != "Not Specified")
r = r.Where(p => p.UnitUserField2 == subcategory);
I'm just not sure of the SQL that is firing in the conditional where clause.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您手头有数据库上下文,您可以尝试:
If you have the database context at hand you could try:
如果您调试代码,您可以放置一个断点并分析
r
的值,其中将包含实际的 SQL 代码。if you debug your code you can put a breakpoint and analyze the value of
r
, which will have the actual SQL code in it.除了上述选项之外,您还可以运行 SQL 分析器并查看通过线路发送到数据库的实际 SQL。
As well as the above options, you can also run up SQL profiler and see the actual SQL sent down the wire to the DB.
如果您使用 LINQ to SQL,则可以设置
DataContext.Log
属性。当您执行查询时,这将记录 SQL:If you use LINQ to SQL you can set the
DataContext.Log
property. This will log the SQL when you execute the query: