linq group have a question?

1 posts, 0 answers
  1. 界 avatar
    1 posts
    Member since:
    Aug 2016

    Posted 25 Aug Link to this post

    first! my english so poor...

    please excuse me= ="

    i need select  a( List<DeputyLeaveItem> source) and group by it

    but it sometimes OK~sometimes error:object reference not set to an instance of an object

    this is my code:

    var resultList = (from a in source.ToList()
                              group a by new { a.leaveStartDate, a.leaveEndDate }
                                  into b
                                  select new LeaveItem()
                                      showOn = DateTime.Now.Date <= Convert.ToDateTime(b.First().leaveEndDate).Date ? "Y" : "N",
                                      delFlag = DateTime.Now.Date <= Convert.ToDateTime(b.First().leaveEndDate).Date,
                                      leaveStartDate = b.First().leaveStartDate,
                                      leaveEndDate = b.First().leaveEndDate
                                  }).OrderByDescending(x => x.leaveStartDate).ToList();


Back to Top