Lennon Ferreira Lennon Ferreira - 2 months ago 30
C# Question

ORA-00904 invalid identifier on generated query from linq

I have this linq :-

var query = from r in Ctx.Reg
select new
{
IdReg = r.Id,
...
Status1 = r.Hist.OrderByDescending(o => o.Id).Take(1).Any(x=> x.Status == 2),
Status2 = r.Hist.OrderByDescending(o => o.Id).Skip(1).Take(1).Any(x=> x.Status == 5)
};


The generated query contains:

WHERE ("Extent1"."REP_ID" = "Extent2"."REP_ID")


I'm getting the message


ORA-00904: "Extent1"."REP_ID".


Both columns exists and have the same datatype.
What can I do for this issue ?

Answer

I don't know exactly why, but it works:

var query = from r in Ctx.Reg
            select new
            {
                IdReg = r.Id,
                ...
                Status1 = Ctx.RegHist.OrderByDescending(o => o.Id).Take(1).Any(x=> x.RegId == r.Id && x.Status == 2),
                Status2 = Ctx.RegHist.OrderByDescending(o => o.Id).Skip(1).Take(1).Any(x=> x.RegId == r.Id && x.Status == 5)
            };