我怎样才能找到哪些俱乐部有最多的球员被质疑。因此,查询将包含所有拥有最多球员的俱乐部。例如,如果第一俱乐部有3名球员,第二俱乐部有5名球员,第三俱乐部也有5名球员,那么查询中将有第二和第三俱乐部。我需要归还俱乐部的名单。
public List<Club> ClubWithMostPlayers()
{
using (var context = new dataContext())
{
var query = ?????
return query.ToList();
}
}这些是我使用的类
public class Player
{
public int PlayerId { get; set; }
public string name { get; set; }
public string surname { get; set; }
public int yearOfBirth { get; set; }
public virtual List<PlayerClub> playerClub { get; set; }
}
public class Club
{
public int ClubId { get; set; }
public string name { get; set; }
public string stadium { get; set; }
public int yearOfConstruction { get; set; }
public virtual List<PlayerClub> playerClub { get; set; }
}
public class PlayerClub
{
public int PlayerClubId { get; set; }
public int PlayerId { get; set; }
public int ClubId { get; set; }
public virtual Player player { get; set; }
public virtual Club club { get; set; }
public int from { get; set; }
public int to { get; set; }
public int appearances { get; set; }
}我知道如何使用SQL,但不知道在LINQ中如何做。
谢谢你的帮助
发布于 2016-11-03 01:04:24
把你的查询分成两部分怎么样?
// get number of maximum number of players in one club
var count = context.Clubs.Select(c => c.playerClub.Count()).Max();
// get clubs with specific number of players
var query = context.Clubs
.Where(c => c.playerClub.Count() == count);https://stackoverflow.com/questions/40392171
复制相似问题