简体   繁体   English

如何使用扩展方法在.NET Entity Framework中的多个列上联接?

[英]How to join on multiple columns in .NET Entity Framework with extension methods?

I am trying to perform a query like this: 我正在尝试执行这样的查询:

SELECT *
FROM pd AS p
JOIN wh AS w
ON p.ID = w.ID
AND p.ln = w.ln
AND p.wID = w.WID
WHERE w.zID = '1234'

So far I can access the tables like this: 到目前为止,我可以像这样访问表:

WEntity entity = new WEntity();
// I can call the entities like this: entity.pd and entity.wh.

I googled and found examples with one column, eg. 我用谷歌搜索并找到带有一栏的示例,例如。

var data = entity.pd
                 .Join(entity.wh,
                       p => p.ID,
                       w => w.ID,
                       (p, w) => p).Where( ... );

这可能会有所帮助-假设您要执行的操作有几个联接:

post = (From ca In db.be_Categories Join c In db.be_PostCategory On ca.CategoryID Equals (c.CategoryID) Join p In db.be_Posts On c.PostID Equals (p.PostId) Where p.PostRowID = id Select New PostDTO With {.PostCategory = Nothing, .PostDateCreated = p.DateCreated, .PostGuid = p.PostId, .PostId = p.PostRowID, .PostText = p.PostContent, .PostTitle = p.Title}).FirstOrDefault

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM