Prasad Krishnarao

Prasad Krishnarao

  • NA
  • 582
  • 16k

Exception Handling in LINQ

Aug 29 2022 8:23 PM

Hi 

In below LINQ, I wanted to filter the rows which has days value more than 90. But some row might have NULL value in days field. I wanted to handle  those row which has NULL in days field  and  log  the corresponding  row details like name, class ,birthday and skip that row and continue with next row. ( Similar to Continue statement in for each loop)

Could you help to get a solution?

 

var tempItems = (from tmp in dt.AsEnumerable()
                                     where tmp .Field<int>("days") > 90
             
                                     select new
                                     {
                                         Name= tmp["Name"],
                                         class = tmp["class"],
                                         birthdate = tmp["birthdate"],
                                         days= tmp["days"],
                                         amount = tmp["amount"],
                                        
                                     }).GroupBy(n => new { n.Name, n.class });


Answers (2)