Linq Join () with a composite key

I am trying to make a query with two tables

Table Page: Id, LangId (primary key) PageTypeId, PageTypeLangId (foreign key)

PageType table: Id, LangId (primary key)

So how to do this? Here, I missed, just add PageTypeLangId

    return context.Pages
            .Join(context.PageTypes, p => p.PageTypeId, pT => pT.Id,(p, pT) => new { p, pT })

I would like:

 select * from Page inner join PageType on Page.PageTypeId=PageType.Id and     Page.PageTypeLangId=PageType.LangId

Thank you for your help!

+5
source share
1 answer

The following should work:

return context.Pages
              .Where(x => x.PageTypeLangId.HasValue)
              .Join(context.PageTypes,
                    p => new { Id = p.PageTypeId,
                               LangId = p.PageTypeLangId.Value },
                    pT => new { pT.Id, pT.LangId },
                    (p, pT) => new { p, pT });
+8
source

All Articles