How to debug a LINQ Statement

后端 未结 9 1250
自闭症患者
自闭症患者 2020-12-04 23:47

I have a Linq to objects statement

 var confirm = from l in lines.Lines 
 where (l.LineNumber == startline.LineNumber) || (l.LineNumber == endline.LineNumber         


        
9条回答
  •  盖世英雄少女心
    2020-12-05 00:39

    Yes it is indeed possible to pause execution midway through a linq query.

    Convert your linq to query style using lambda expressions and insert a Select statement that returns itself somewhere after the point in the linq that you want to debug. Some sample code will make it clearer -

            var query = dataset.Tables[0].AsEnumerable()
                .Where (i=> i.Field("Project").Contains("070932.01"))
     //         .Select(i =>
     //         {return i;}
     //           )
                .Select (i=>i.Field("City"));
    

    Then uncomment the commented lines. Make sure the {return i;} is on its own line and insert a debug point there. You can put this select at any point in your long, complicated linq query.

提交回复
热议问题