0

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

I want to translate this sql to linq but failed. How can I do translate?

4

1 回答 1

0

我认为这会做到这一点,但你应该检查 linq 正在生成什么 sql。

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)
于 2013-09-06T14:50:02.390 回答