/ / Wie kann ich SQL in LINQ übersetzen? - linq

Wie übersetzt man SQL nach LINQ? - linq

sql

select * from (select * from tabla limit 1) as a inner join table b on a.id = b.id where a.id = id

LINQ

from s in tableA
join c in (from a in tableB where a.id==id select a).FirstOrDefault() on s.id equals c.id
where s.id == id
select s

Ich möchte diese SQL in Linq übersetzen, aber es ist fehlgeschlagen. Wie kann ich übersetzen?

Antworten:

0 für die Antwort № 1

Ich denke, das wird es tun, aber Sie sollten prüfen, welche SQL von Linq generiert wird.

a = tableA.FirstOrDefault();

//First option
tableB.Where(xb => xb.id = a.id)
.Select(xb => new {a = a, b = xb})
.Where(abx => abx.a.id == id)

//Second option
tableB.Select(xb => new {a = a, b = xb})
.Where(abx => abx.a.id == id && abx.a.id = abx.b.id)