How to debug a Linq Lambda Expression?

2019-03-08 20:07发布

I am using Entity Framework and Linq to Entitites.

I would like to know if there is any way in Visual Studio 2012 to debug this code, step by step. At the moment when placing a break point, the cursor goes over it but does not step inside.

I am more interested to see the value of x.e... not the sql generated for example.

Notes: I'm fine with using other tools or Visual Studio plugins.

          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条回答
地球回转人心会变
2楼-- · 2019-03-08 20:48

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.

查看更多
疯言疯语
3楼-- · 2019-03-08 20:50

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.

查看更多
登录 后发表回答