我正在使用 Entity Framework 和 Linq to Entitites。
我想知道在 Visual Studio 2012 中是否有任何方法可以逐步调试这段代码。 放置断点的瞬间,光标越过断点,但没有进入。
我更感兴趣的是 x.e 的值...而不是生成的 sql。
注意:我可以使用其他工具或 Visual Studio 插件。
IEnumerable<EventPushNotification> eventToPushCollage = eventsForEvaluation
.GroupJoin(eventCustomRepository.FindAllPushedEvents(),
e => e.Id,
p => p.PushedEventId,
(e, p) => new { e, p })
.Where(x => x.e.DateTimeStart > currentDateTime &&
currentDateTime >= x.e.DateTimeStart.AddMinutes(defaultReminders) && // Data from default reminder for collage event in web.config
x.p.Count() == 0) // Check if the Event has not being already pushed
.Select(y => new EventPushNotification
{
Id = y.e.Id,
EventTitle = y.e.EventTitle,
DateTimeStart = y.e.DateTimeStart,
DateTimeEnd = y.e.DateTimeEnd,
Location = y.e.Location,
Description = y.e.Description,
DeviceToken = y.e.DeviceToken
});
最佳答案
请务必阅读有关此问题的官方 MSDN 文档:
请在 Visual Studio 的用户意见页面上为这个建议投票:
Allon Guralnek 2014 年 3 月 18 日下午 12:37 关于仅使用键盘设置断点的方法的评论:
@Anonymous: You can do this today by setting a breakpoint inside the lambda, thereby enabling you to inspect each value that comes in and out of the lambda. As far as I know, you can't set a breakpoint inside a lambda using the mouse, you must use the keyboard. Put the cursor inside the lambda body (e.g. on the first token, or anything after the => and the whitespace that follows) then press F9 (or whatever keyboard shortcut you use to place a breakpoint). Only the inside of the lambda statement will turn red, and the debugger will break there for each item the lambda is evaluated against (so for an array of 100 items, using .Where() will cause the breakpoint to hit 100 times).
这是在我当前的 Visual Studio 2013 中执行的操作:
如您所见,它运行良好,并允许我们查看正在测试的给定属性的值。这肯定是一个很棒的工具/救生员! :)
关于c# - 如何调试 Linq Lambda 表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17231101/