EF 5 LINQ在ON子句中连接具有多个条件的表

时间:2013-03-21 01:48:31

标签: linq-to-entities entity-framework-5 asp.net-4.5

我试图在我的on子句中使用两个条件来连接表,但是我得到了错误

  

运营商&&不能应用于字节和字节类型的操作数

如何在ON子句中使用多个条件来连接表?

                    using (var db = new ReleaseInfo())
                {
                    lvReleaseInfo = (from r in db.ReleaseTranslations
                                     join c in db.Countries
                                     on r.SectionRelease.ReleaseCountryID equals c.CountryID && c.CultureID equals CultureID
                                     join pf in db.Platforms
                                     on r.SectionRelease.PlatformID equals pf.PlatformID && pf.PlatformID equals CultureID
                                     join pub in db.Publishers
                                     on r.SectionRelease.PublisherID equals pub.PublisherID && pub.CultureID equals CultureID
                                     where r.ReleaseID == SectionID && r.CultureID == CultureID
                }

1 个答案:

答案 0 :(得分:1)

您可以为equi-join的每一侧创建一个匿名类型:

lvReleaseInfo = (from r in db.ReleaseTranslations
                 join c in db.Countries
                 on new {CountryID = r.SectionRelease.ReleaseCountryID, CultureID} equals new {c.CountryID, c.CultureID}
                 join pf in db.Platforms
                 on new {r.SectionRelease.PlatformID, CultureID} equals new {pf.PlatformID, CultureID = pf.PlatformID}
                 join pub in db.Publishers
                 on new {r.SectionRelease.PublisherID, r.CultureID} equals new {pub.PublisherID, pub.CultureID}
                 where r.ReleaseID == SectionID && r.CultureID == CultureID