I am using Entity Framework and Linq to Entitites.
我使用实体框架和Linq到Entitites。
I would like to know if there is any way in Visual Studio 2012 to debug, step by step this code. At the moment when placing a break point, the cursor go over it but not step inside.
我想知道在Visual Studio 2012中是否有任何方法可以调试这个代码。在放置断点时,光标会越过它,但不会进入内部。
I am more interested to see the value of x.e... not the sql generate for example.
我更感兴趣的是x的值。不是sql生成的例子。
Notes: Others free tolls or Visual Studio plugins are fine too
备注:其他免费收费或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
});
8 个解决方案
#1
6
You can't debug a Lambda expression if your are using a Linq2Entities provider.
如果您使用的是linq2entity提供程序,那么您无法调试Lambda表达式。
But you can take a look at what SQL it translate into. Also if you are willing to suffer a performance hit - you could load it all into Linq to obejcts - and do a Step by step
但是您可以看看它转换成什么SQL。此外,如果您愿意遭受性能打击——您可以将其加载到Linq到obejcts——并逐步执行。
#2
68
Make sure you read the official MSDN doc on this matter:
确保你阅读了关于这个问题的官方MSDN文档:
调试LINQ
and please vote for this suggestion on Visual Studio's User Voice page:
请在Visual Studio的用户语音页面上投票支持这个建议:
调试Lambda表达式
Allon Guralnek comments on March 18, 2014 12:37 PM about a way of setting a breakpoint with the keyboard only:
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).
@Anonymous:您可以通过在lambda中设置一个断点来实现这一点,从而使您能够检查进出lambda的每个值。据我所知,您不能在使用鼠标的lambda中设置断点,您必须使用键盘。将光标放在lambda体中(例如,在第一个令牌上,或在=>和后面的空格之后),然后按F9(或任何用于放置断点的快捷键)。只有lambda语句的内部会变红,并且调试器会在对lambda的每一项进行评估(所以对于一个包含100个条目的数组,使用. where()会导致断点达到100次)。
Here's it in action in my current Visual Studio 2013:
这是我现在的Visual Studio 2013的行动:
As you can see it works pretty well and allows us to see the value of a given property being tested. This is for sure an awesome tool/life saver! :)
正如您所看到的,它运行得非常好,并且允许我们看到正在测试的给定属性的值。这是一个非常棒的工具/救生圈!:)
#3
4
You can add breakpoints on any of your own code.
您可以在自己的任何代码中添加断点。
So put the cursor at 'x.e', and press F9.
把光标放到x上。e”,按f8。
#4
3
For any future readers, this has now been included in Visual Studio. Starting from Visual Studio 2015 Preview, you can now debug lambda expression during debugging. All debug windows including Watch, QuickWatch and Immediate support lambda expression evaluation. You can read more about this here.
对于未来的读者来说,这已经被包括在Visual Studio中了。从Visual Studio 2015预览开始,您现在可以在调试期间调试lambda表达式。所有的调试窗口,包括手表,QuickWatch和即时支持lambda表达式的评估。你可以在这里读到更多。
#5
1
No there is no way to see values of x
nor e
variables because linq to orm is not executed it is translated/interpreted to generate an sql query.
没有办法看到x或e变量的值,因为没有执行linq to orm,它被翻译/解释生成一个sql查询。
#6
1
You can debug lambda expressions in Visual Studio 2015.
您可以在Visual Studio 2015中调试lambda表达式。
http://blogs.msdn.com/b/visualstudioalm/archive/2014/11/12/support - -调试- lambda表达式和- 2015. aspx -视觉工作室
#7
0
I don't know how to this directly in Visual Studio, but you should have a look at LinqPad: http://www.linqpad.net/
我不知道如何直接在Visual Studio中,但是你应该看看LinqPad: http://www.linqpad.net/。
#8
0
I had to 'Enable Just My Code' in Tools/Options/Debugging. To see the different results between Lambda-methods, I've put .ToList() between them.
我必须在工具/选项/调试中“启用我的代码”。为了查看lambda方法之间的不同结果,我将. tolist()放在它们之间。
#1
6
You can't debug a Lambda expression if your are using a Linq2Entities provider.
如果您使用的是linq2entity提供程序,那么您无法调试Lambda表达式。
But you can take a look at what SQL it translate into. Also if you are willing to suffer a performance hit - you could load it all into Linq to obejcts - and do a Step by step
但是您可以看看它转换成什么SQL。此外,如果您愿意遭受性能打击——您可以将其加载到Linq到obejcts——并逐步执行。
#2
68
Make sure you read the official MSDN doc on this matter:
确保你阅读了关于这个问题的官方MSDN文档:
调试LINQ
and please vote for this suggestion on Visual Studio's User Voice page:
请在Visual Studio的用户语音页面上投票支持这个建议:
调试Lambda表达式
Allon Guralnek comments on March 18, 2014 12:37 PM about a way of setting a breakpoint with the keyboard only:
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).
@Anonymous:您可以通过在lambda中设置一个断点来实现这一点,从而使您能够检查进出lambda的每个值。据我所知,您不能在使用鼠标的lambda中设置断点,您必须使用键盘。将光标放在lambda体中(例如,在第一个令牌上,或在=>和后面的空格之后),然后按F9(或任何用于放置断点的快捷键)。只有lambda语句的内部会变红,并且调试器会在对lambda的每一项进行评估(所以对于一个包含100个条目的数组,使用. where()会导致断点达到100次)。
Here's it in action in my current Visual Studio 2013:
这是我现在的Visual Studio 2013的行动:
As you can see it works pretty well and allows us to see the value of a given property being tested. This is for sure an awesome tool/life saver! :)
正如您所看到的,它运行得非常好,并且允许我们看到正在测试的给定属性的值。这是一个非常棒的工具/救生圈!:)
#3
4
You can add breakpoints on any of your own code.
您可以在自己的任何代码中添加断点。
So put the cursor at 'x.e', and press F9.
把光标放到x上。e”,按f8。
#4
3
For any future readers, this has now been included in Visual Studio. Starting from Visual Studio 2015 Preview, you can now debug lambda expression during debugging. All debug windows including Watch, QuickWatch and Immediate support lambda expression evaluation. You can read more about this here.
对于未来的读者来说,这已经被包括在Visual Studio中了。从Visual Studio 2015预览开始,您现在可以在调试期间调试lambda表达式。所有的调试窗口,包括手表,QuickWatch和即时支持lambda表达式的评估。你可以在这里读到更多。
#5
1
No there is no way to see values of x
nor e
variables because linq to orm is not executed it is translated/interpreted to generate an sql query.
没有办法看到x或e变量的值,因为没有执行linq to orm,它被翻译/解释生成一个sql查询。
#6
1
You can debug lambda expressions in Visual Studio 2015.
您可以在Visual Studio 2015中调试lambda表达式。
http://blogs.msdn.com/b/visualstudioalm/archive/2014/11/12/support - -调试- lambda表达式和- 2015. aspx -视觉工作室
#7
0
I don't know how to this directly in Visual Studio, but you should have a look at LinqPad: http://www.linqpad.net/
我不知道如何直接在Visual Studio中,但是你应该看看LinqPad: http://www.linqpad.net/。
#8
0
I had to 'Enable Just My Code' in Tools/Options/Debugging. To see the different results between Lambda-methods, I've put .ToList() between them.
我必须在工具/选项/调试中“启用我的代码”。为了查看lambda方法之间的不同结果,我将. tolist()放在它们之间。