I am trying to get all records (from single table) by latest date using LINQ but having some issue. For eg if table has 2 rows with latest date then I need to fetch these two rows on certain criteria. Please help
Here is my code.
var q = (from n in Table
where n.CustomerId == customerId && n.Isactive==true
group n by new { n.CustomerId, n.ConsentId } into grp
select new
{
// select all fields
grp.Key.ConsentId,
grp.Key.CustomerId,
Date = grp.Max(t=>t.CreatedOn)
}).ToList();