I need a query like this in lambda
SELECT ClienteId --Aqui eu tenho varios campos do Cliente e estagioprocesso
FROM Cliente
WHERE ((SELECT TOP (1) EP
FROM estagioprocesso
WHERE (estagioprocesso.ClienteID = Cliente.ClienteId)
ORDER BY estagioprocesso.ID DESC)= 2)
That is, I check in the StepProcess table which is the last EP of that customer (order by ID DESC) I get only 1 (top 1) and check this EP if it is equal to the number I want to return.
I want to bring all the steps of the clients that the most recent step has the EP = id (2).
I tried:
int id = 2;
var EP = db.EtapaProcess
.Include(t => t.Cliente)
.OrderByDescending(t => t.EP).Take(1).Where(x => x.EP == id)
.ToList();
But it does not work. Ex: There are 188 records that have already passed through EP = 2, but with EP = 2 only 5 records and with the above query it returns 0