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.
在下面的代码中,当它到达foreach循环时,我运行调试器,直到它突出显示“结果”,然后在那个点停止运行代码,并且没有抛出任何异常。
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){
...
}
3 个解决方案
#1
3
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.
调试Linq查询时,如果您不尝试在调试器中检查IQueryable的内容,而是将其简化为列表或数组,那么调试Linq查询通常会使工作变得更简单。
Try putting:
试着把:
var resultList = result.ToList();
..after your query; put a breakpoint directly after that line; and then see in the debugger what the contents of resultList
are.
. .后你的查询;将断点直接放在该线之后;然后在调试器中查看resultList的内容是什么。
#2
1
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?
它是否超越了foreach循环?
#3
0
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?
也许您正在等待来自数据库的行,并且存在锁争用,导致应用程序停止并等待正在访问的表上的锁释放。这不是错误条件,不应抛出异常。例如,是否有并发写入要访问的表的写入器或获得独占表锁的其他访问器,特别是在长事务中?
#1
3
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.
调试Linq查询时,如果您不尝试在调试器中检查IQueryable的内容,而是将其简化为列表或数组,那么调试Linq查询通常会使工作变得更简单。
Try putting:
试着把:
var resultList = result.ToList();
..after your query; put a breakpoint directly after that line; and then see in the debugger what the contents of resultList
are.
. .后你的查询;将断点直接放在该线之后;然后在调试器中查看resultList的内容是什么。
#2
1
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?
它是否超越了foreach循环?
#3
0
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?
也许您正在等待来自数据库的行,并且存在锁争用,导致应用程序停止并等待正在访问的表上的锁释放。这不是错误条件,不应抛出异常。例如,是否有并发写入要访问的表的写入器或获得独占表锁的其他访问器,特别是在长事务中?