I'm trying to make a request with two tables
Table Page : Id, LangId (primary key) PageTypeId, PageTypeLangId (foreign key)
Table PageType : Id, LangId (primary key)
So How to do ? Here, i miss just do 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
Thanks for your help !
This is accomplished by using a composite key.
In LINQ, an inner join is used to serve a result which contains only those elements from the first data source that appears only one time in the second data source. And if an element of the first data source does not have matching elements, then it will not appear in the result data set.
When you use the LINQ join clause in the query expression syntax to combine two sets of related information, you perform an inner join.
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 });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With