2
I need a consult like that on the 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 table Etapaprocess which is the last EP of this client (order by ID DESC) I take only 1 (top 1) and I check this EP if it is equal to the number I want return.
I want to bring all customer steps that the latest step has EP = id (2).
I tried to:
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 doesn’t work. Ex: There are 188 records that have already passed the EP=2, but that are with EP=2 only 5 records and with the above query returns me 0
It wouldn’t just be changing . Tolist(); to . Firstordefault();
– PauloHDSousa
I don’t think the query even processes, but returns 0, while the pattern I wanted would return 5 records. Looking at the query it generates by Diagnostic Tools is a complex query and there is nothing..
– Dorathoto
Are you sure you have x.EP == id? Try searching without include
– PauloHDSousa
actually x.EP ==id (in case id=2) has 188 records, but I want clients that the last Ep is ID=2 ai would only have 5..
– Dorathoto
Do so var EP = db.EtapaProcess.Take(1). Where(x => x.EP == id) . Tolist();
– PauloHDSousa
It’s almost... but I must get the last (1) customer id.. that is, I see there in the table I order by order autonumerable by desc return only 1 and then I check what is this EP if it is the 2 in case I recover the information... I will try to improve my doubt to be more clear.
– Dorathoto
All right, try posting what you want with PURE SQL
– PauloHDSousa
Let’s go continue this discussion in chat.
– PauloHDSousa