Hi
I have below linq query & i want to get only Last Record out of List
C#
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
C#
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

Jignesh KumarRank #91 · 22.9K reputationPosted Apr 2, 2023, 3:12 AM EDT
Hi,
Please try this one,
SessionDeliveryCalendar Result = (from t in context.SessionDeliveryCalendars where t.IsActive && t.GroupID == GroupID && t.ModuleID == ModuleID && !t.Deleted && t.CurrentStatus == "Completed" orderby t.SessionDate,t.SessionStartTime select t).ToList().LastOrDefault(); return Result;