0
I’m in need and I’m having trouble getting this sql with subquery and doing the same thing in c# Entity.
SELECT Id,Nome,
(SELECT Count(Id) FROM Pedidos
WHERE Pedidos.ColaboradorId = Colaborador.Id) AS NumeroPedidos
FROM Colaborador
ORDER BY Nome DESC;
I need to transform this SQL above.
var retornoColaborador = db.Colaboradores.Where(a => a.Id == db.Pedidos.Where(b => b.ColaboradorId == a.Id).Count());
I tried to do something like this but it didn’t work.
I use the Linqpad to help you build these expressions, it can help you: http://www.linqpad.net/
– Ricardo Pontual
What does this linqpad do?
– gabrielfalieri
is a tool that helps you test code, you can connect in the database and go assembling the expressions or Linq and it will show the corresponding sql query
– Ricardo Pontual
Too much top. thanks for the tip
– gabrielfalieri
if within
Colaborador
you havePedidos
just select Employees, and the number of orders would becolaborador.Pedidos.Count
– Rovann Linhalis