0

我有三张桌子。我必须使用 Linq 语句检索数据。我的三个表名是 A、B、C。我根据 id 连接了连接两个表 A 和 B 的连接,如下所示:

select ol, fN, LN, ci, co
from member
join details
on member_id = details_id
where details_id in
(select contacts_id from contacts where
contacts_id1 = 1 and contacts_usr_id = 1)

我能够根据where条件编写查询,如何为内部 while 条件编写查询?

4

2 回答 2

1

你可以试试这个:

      var idlist = (from tbl in table3
                    where tbl.usr_id == 1 && tbl.contacts_id == 1
                    select tbl.contacts_id ).ToList();

     var x = from A in table1
              from B in table2 where A.user_id == B.user_id                
              && idlist.Contains(A.user_id)
              select new { a = A.a, b = A.b, c = A.c, d = B.d, e = B.e };

检查并让我知道这是否有效。

于 2012-06-14T12:59:35.493 回答
0

尝试颠倒查询。以下情况如何:

var query = 
   from t3 in table3
   where t3.user_id = 1 && t3.contacts_id = 1
   join t2 in table2 on t3.contacts_id equals t2.usr_id
   join t1 in table1 on t2.usr_id equals t1.userid
   select new {t2.a, t2.b, t2.c, t1.d, t1.e};
于 2012-06-15T15:37:09.927 回答