score:1

Accepted answer

Ok. The only solution, which is what I found while reading in the initial table to the list. Unfortunately, not quite what I meant, but it works.

 AIds = (from x in 
        (
           context.RISK_T_ASSESS_HIST.Where(x => x.ID_RISKOBJECT.HasValue && x.F_CREATEDON >= Freq.StartDate && x.F_CREATEDON <= Freq.EndDate)
           .Select(x => new { x.ID_RISKOBJECT, x.F_CREATEDON, x.F_STATUS }).ToList()
        )      
        group x by x.ID_RISKOBJECT into gr
        let lastCreated = gr.Max(p => p.F_CREATEDON)
        select new
        {
           ObjId = gr.Key
           ,
           LastStatus = gr.Where(p => p.F_CREATEDON == lastCreated && p.ID_RISKOBJECT == gr.Key).Select(p => p.F_STATUS).FirstOrDefault()
        }).Where(x => x.LastStatus == 0 || x.LastStatus == 1).Select(x => x.ObjId.Value).ToArray();

This issue Entity Framework and will be passed as an error on their forum.


Related Articles