无法调试我的 Linq 查询?
在下面的代码中,当进入 foreach 循环时,我运行调试器,直到它突出显示“结果”,然后它就停止运行代码,并且没有抛出异常或任何异常。
我真的不知道为什么当这里出现问题时它不会给我任何错误消息。
var result =
from a in db.table
select new {table = a};
foreach(var row in result){
...
}
In my code below, when it gets to the foreach loop, I run my debugger until it highlights "result" and then it just stops running the code at that point, and there are no exceptions thrown or anything.
I really have no idea why it would not give me any error messages when there is something going wrong here.
var result =
from a in db.table
select new {table = a};
foreach(var row in result){
...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
调试 Linq 查询时,如果您不尝试在调试器中检查
IQueryable
的内容,而是将其展开为列表或数组,通常会更轻松。尝试将:
..放在查询之后;直接在该行之后放置一个断点;然后在调试器中查看
resultList
的内容是什么。When debugging Linq queries, it often makes life easier if, instead of trying to examine the contents of your
IQueryable
in the debugger, you flatten it out to a list or array.Try putting:
..after your query; put a breakpoint directly after that line; and then see in the debugger what the contents of
resultList
are.我猜它实际上是在遍历列表。如果您有一个大表或一个复杂的查询,则需要一段时间(秒)才能执行。
它是否超出了 foreach 循环?
I would guess it's actually traversing over the list. If you have a large table or a complicated query it will take a while (seconds) to execute.
Does it ever go beyond the foreach loop?
也许您正在等待来自数据库的行,并且存在锁争用,导致您的应用程序停止并等待您正在访问的表上的锁被释放。这不是错误情况,不应引发任何异常。例如,是否存在并发写入您尝试访问的表的写入器或已获取独占表锁的其他访问器,尤其是在长事务中?
Perhaps you are waiting for rows to come from a database, and there is lock contention causing your app to stall and wait for the lock(s) on the table you are accessing to be released. That is not an error condition and no exception should be thrown. For example, are there writers that are concurrently writing to the table you are trying to access or other accessors that have acquired an exclusive table lock, especially in a long transaction?