-2
我有兩組數據:trainedOfficers
和officersToTrain
。這些數據集共用一個ClubId
。我試圖確保trainedOfficers
不會出現在officersToTrain
中,所以我想執行正確的外連接。綜觀這一形象:如何使用linq執行右連接外連接
- A = trainedOfficers
- B = officersToTrain
我曾嘗試做下面的查詢,但它產生任何結果。
public void SetTrainedClubOfficers(ILookup<ClubID, ClubOfficerAuthority> clubsAuthorityLookup)
{
var clubIds = clubsAuthorityLookup.Select(x => x.Key);
var trainedOfficers = GetTrainedClubOfficers(clubIds.ToArray());
var clubsToTrain = from trainedOfficer in trainedOfficers
join officer in clubsAuthorityLookup
on trainedOfficer.Key equals officer.Key into joined
from officer in joined.DefaultIfEmpty()
select new
{
ClubId = officer.Key,
Officers = officer.Select(club => club)
};
}
如何獲得正確的外部連接?
完全同意最後一段。這是一個糟糕的設計。 –