This topic has been archived. It cannot be replied.
-
工作学习 / 学科技术讨论 / C#问题, 如何把多个表的join转换成LINQ?select * from table_a A
inner join table_b B on A.id1=B.id1 and A.id2=B.id2
left join table_c C on A.id1=C.id1 and A.id2=C.id2
left join table_d D on B.id1=D.id1 and B.id2=D.id2
哪位大侠帮忙写成LINQ?
-tonyhao(tonyhao);
2009-12-27
{205}
(#5766235@0)
-
Here is a link explain how to do left and right join. I believe it is what you are looking for.
-winstonwx(绿芒果);
2009-12-27
(#5766742@0)
-
这个是2个表的join, 我说的是多个表的.
-tonyhao(tonyhao);
2009-12-28
(#5767075@0)
-
The easiest way is join the first 2 tables first then use the result to join the third. Before you use ToList() or getting the content It won't actually execute the query.So no matter how many lines of LINQ you use for this query, they will be sent to server once only before you really asking the content.
I did not actually test this query, but for sure it will work.
-winstonwx(绿芒果);
2009-12-28
{201}
(#5767086@0)
-
If you don’t need filter out missing records in C and D, it’s simple.var q = from a in A
join b in B on a.ID equals b.ID
join c in C on a.ID equals c.ID into g1
join d in D on a.ID equals d.ID into g2
select new { a, b, g1, g2 };
-deep_blue(BLUE);
2009-12-28
{196}
(#5767084@0)
-
如果C和D都和A join, 可以通过编译. 不然, 有编译错误. Compiler Error CS1937
-tonyhao(tonyhao);
2009-12-30
(#5770511@0)