Ramco Ramco

Ramco Ramco

  • 462
  • 2.9k
  • 408.9k

How to get Last Record

Apr 2 2023 6:41 AM

Hi

  I have below linq query & i want to get only Last Record out of List

SessionDeliveryCalendar Result = (from t in context.SessionDeliveryCalendars
                                                    where t.IsActive == true && t.GroupID == GroupID && t.ModuleID == ModuleID && t.Deleted == false
                                                    && t.CurrentStatus == "Completed"
                                                    orderby t.SessionDate,t.SessionStartTime  descending                                                   select t).FirstOrDefault();
            return Result;

I am trying like below but it is giving error The query operator lastordefualt is not supported

SessionDeliveryCalendar Result = (from t in context.SessionDeliveryCalendars
                                                    where t.IsActive == true && t.GroupID == GroupID && t.ModuleID == ModuleID && t.Deleted == false
                                                    && t.CurrentStatus == "Completed"
                                                    orderby t.SessionDate,t.SessionStartTime 
                                                    select t).LastOrDefault();
            return Result;

Thanks


Answers (1)