1

我在 RAW sql 中有这个查询:

SELECT DISTINCT b.SourceUser_Id
FROM UserInteractions b
JOIN UserInteractions x on x.SourceUser_Id=1 and x.TargetUser_Id=b.SourceUser_Id

UserInteractions 是一个表,它以多对多的关系将 User 表与其自身连接起来(以创建友谊关系)。

此查询返回所有相互的 UserInteractions(即:它仅返回目标与您成为朋友的 UserInteractions。

sql 查询运行良好,但我不知道如何将其转换为 EntityFramework 的 lambda。

我需要一种方法让这个东西与 Join() 方法一起工作。

4

1 回答 1

1

就像是:

var s = from b in UserInteractions 
             join x in UserInteractions on b.TargetUser_Id equals x.TargetUser_Id
             where x.SourceUser_Id == 1
                         select b.SourceUser_Id;

拉姆达:

var s = query.Join(db.UserInteractions,
            f => f.TargetUser,
            p => p.SourceUser,
            (f, p) => new {f, p }).Where(x=>x.f.SourceUser == 1).Select(p=>p.f);
于 2013-07-21T01:31:52.013 回答