如何将以下sql转换为linq语句?
SELECT Column1, Column2
FROM Table1 as A
INNER JOIN (SELECT * FROM Table2 WHERE ColumnB = "Something1") B on A.Column1 = B.ColumnA
WHERE A.Column3 = "Something2"
答案 0 :(得分:1)
好吧,对于内连接,只需
就可以实现更好的可读性 select a.Column1, a.Column2
from Table1 a
join Table2 b on b.Column1 = a.Column1
where a.Column3 = 'Something2' and b.ColumnB = 'Something1'
现在,您可以使用伪linq
from a in Table1
join b in Table2 on a.Column1 equals b.Column1
where b.ColumnB == "Something1" and a.Column3 = ="Something2"
select new {
col1 = a.Column1,
col2 = a.Column2
};
或
from a in Table1.Where(t => t.Column3 == "Something2"
join b in Table2.Where(t => t.ColumnB == "Something1")
on a.Column1 equals b.Column1
select new {
col1 = a.Column1,
col2 = a.Column2
};