以下查询返回第二个select查询中的重复结果。Linq查询返回重复结果
国家有0..1 to *
与联赛的关系。
联盟有1 to *
与userLeagues的关系。
return from ul in userLeagues
select new Map.Country
{
id = ul.Country.CountryId,
name = ul.Country.Common_Name,
leagues = userLeagues.Where(x => x.CountryId.Value == ul.CountryId.Value)
.Select(x => new Map.League
{
id = x.LeagueID,
name = x.leagueNameEN,
})
};
我试过用Distinct
没有运气。 看来,无论是我必须使用不同的或GROUPBY countryId
输出是如
[
{
"id": 1,
"name": "Europe",
"leagues": [
{
"id": 2,
"name": "Champions League",
},
{
"id": 3,
"name": "Europa league",
}
]
},
{
"id": 1,
"name": "Europe",
"leagues": [
{
"id": 2,
"name": "Champions League",
},
{
"id": 3,
"name": "Europa league",
}
]
}
]
也许尝试加入'.ToList()'你要指定为'leagues'查询结束。但是,“重复”是什么意思?你是说每个国家都得到所有的用户联盟,或者每个国家都获得属于最后一个国家的所有用户联盟,或者是什么? –
重复在哪些列/属性? –
你不能使用group by来删除重复的结果吗? –