[英]The LINQ expression g.Inner)' could not be translated. Either rewrite the query in a form that can be translate
Help me fix or release this issue My Task: correct guesses/games played If the success rate is the same - player with fewer total tries is ranked higher Input minimum games played N - players will be included in the leaderboard if at least N games are played帮助我修复或发布此问题 我的任务:正确猜测/玩过的游戏 如果成功率相同 - 总尝试次数较少的玩家排名更高玩过
My Players model:我的玩家 model:
[Table("players")]
public class Player
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public string Id { get; set; }
[Required]
[Display(Name = "Player name")]
public string Name { get; set; }
[JsonIgnore]
public List<Game> Games { get; set; }
}
I am creating leaderbords list from Games table, And this is my Games model:我正在从 Games 表中创建排行榜列表,这是我的 Games model:
[Table("games")]
public class Game
{
public Game()
{
this.StartDate = DateTime.Now;
this.Attempts = 0;
this.EndDate = null;
this.Result = GameResultType.InGame;
}
[Key]
public int ID { get; set; }
[Required]
[Display(Name = "Player")]
public Player Player
{
get;
set;
}
[Display(Name = "Count Attempts")]
public int Attempts
{
get;
set;
}
[Required]
[Display(Name = "Random number")]
[JsonIgnore]
public int RandomNumber
{
get;
set;
}
[Display(Name = "Game start datetime")]
public DateTime StartDate
{
get;
set;
}
[Display(Name = "Game end datetime")]
public DateTime? EndDate
{
get;
set;
}
[Display(Name = "Status of the game")]
public StatusType Status
{
get;
set;
}
[Display(Name = "Status of the game")]
public GameResultType Result
{
get;
set;
}
And i should get leaderboards which players played N games我应该得到玩家玩过N场比赛的排行榜
Here is my query:这是我的查询:
var noticesGrouped = _context.Games
.GroupBy(n => n.Player)
.Select(group =>
new
{
PlayerName = group.Key.Name,
Games = group.Key.Games.ToList(),
Count = group.Key.Games.Count()
}).Where(x => x.Games.Count > 1).ToList();
You will need to materialize the objects to allow for LINQ to Object to handle your where statement instead of LINQ to SQL You will need to materialize the objects to allow for LINQ to Object to handle your where statement instead of LINQ to SQL
You can get this working with:您可以使用以下方法:
var noticesGrouped = _context.Games
.GroupBy(n => n.Player)
.Select(group =>
new
{
PlayerName = group.Key.Name,
Games = group.Key.Games.ToList(),
Count = group.Key.Games.Count()
})
.AsEnumerable()
.Where(x => x.Games.Count > 1)
.ToList();
Read more about it here: Are Linq to SQL and Linq to Objects queries the same?在此处阅读有关它的更多信息: Linq 到 SQL 和 Linq 到对象查询是否相同?
And here: The LINQ expression could not be translated and will be evaluated locally在这里: LINQ 表达式无法翻译,将在本地进行评估
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.