/ / ¿Cómo traducir SQL a LINQ? - linq

¿Cómo traducir SQL a 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

Quiero traducir este sql a linq pero falló. ¿Cómo puedo traducir?

Respuestas

0 para la respuesta № 1

Creo que esto lo hará, pero deberías comprobar qué sql está generando linq.

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)