无法调试我的 Linq 查询?

发布于 2024-11-04 01:17:50 字数 243 浏览 0 评论 0原文

在下面的代码中,当进入 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笑饮青盏花 2024-11-11 01:17:50

调试 Linq 查询时,如果您不尝试在调试器中检查 IQueryable 的内容,而是将其展开为列表或数组,通常会更轻松。

尝试将:

var resultList = result.ToList();

..放在查询之后;直接在该行之后放置一个断点;然后在调试器中查看 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:

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.

抚你发端 2024-11-11 01:17:50

我猜它实际上是在遍历列表。如果您有一个大表或一个复杂的查询,则需要一段时间(秒)才能执行。

它是否超出了 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?

往事风中埋 2024-11-11 01:17:50

也许您正在等待来自数据库的行,并且存在锁争用,导致您的应用程序停止并等待您正在访问的表上的锁被释放。这不是错误情况,不应引发任何异常。例如,是否存在并发写入您尝试访问的表的写入器或已获取独占表锁的其他访问器,尤其是在长事务中?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文