开发者

View Lambdas in Visual Studio Debugger

I have the a simple LinqToSQL statement that is not working. Something Like this:

List<MyClass> myList = _ctx.DBList
     .Where(x => x.AGuidID == paramID) 
     .Where(x => x.BBoolVal == false) 
     .ToList();

I look at _ctx.DBList in the debugger and the second item fits both parameters.

Is there a way I can dig into t开发者_开发知识库his more to see what is going wrong?


I would split it into two steps -- the construction of the query, then the assignment to the list. That way you can look at the generated SQL in the debugger and see if it is correct. I sometimes cut/paste (and fix up) into SSMS when I have a query problem to debug.

var q = _ctx.DBList 
     .Where(x => x.AGuidID == paramID)  
     .Where(x => x.BBoolVal == false) 
// view q in the debugger to see the SQL it will generate
var myList = q.ToList();


You basically have 2 options.

You can break the statement apart and look at what's produced at each step:

var p1 = _ctx.DBList.Where(x => x.AGuidID == paramID).ToList();
var p2=p1.Where(x => x.BBoolVal == false).ToList();
// and you just examine each of them in the debugger
// I put ToList() here so you get the actual result

Or you can write your lambda expressions on different lines and put a breakpoint on it then iterate through your code with step in. You'll get a ton more information, but you most likely won't get anything more useful than the 2 arrays above (plus it might take a very long time to get to the actual error if any).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜