简体   繁体   English

无法翻译 LINQ 表达式 g.Inner)'。 以可以翻译的形式重写查询

[英]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.

相关问题 LINQ 无法翻译表达式。 要么以可以翻译的形式重写查询 - LINQ expression could not be translated. Either rewrite the query in a form that can be translated 无法翻译 LINQ 表达式。 要么以可以翻译的形式重写查询 - The LINQ expression could not be translated. Either rewrite the query in a form that can be translated 无法翻译 LINQ 表达式。 要么以可翻译的形式重写查询,要么切换到客户评估 - The LINQ expression could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation 无法翻译 LINQ 表达式。 以可翻译的形式重写查询,或切换到客户端评估 EF Core 3.1 - The LINQ expression could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation EF Core 3.1 无法翻译 Orderby。 要么以可以翻译的形式重写查询 - Orderby could not be translated. Either rewrite the query in a form that can be translated 实体框架,Linq 查询抛出异常“无法翻译。要么以可以翻译的形式重写查询 - Entity Framework, Linq query is throwing exception "could not be translated. Either rewrite the query in a form that can be translated 错误 - 无法翻译 EF Core。 要么以可以翻译的形式重写查询 - ERROR - EF Core could not be translated. Either rewrite the query in a form that can be translated 得到“无法翻译。 以可翻译的形式重写查询”,.NET Corel 中的异常 - Getting “could not be translated. Either rewrite the query in a form that can be translated”, exception in .NET Corel 无法翻译 LINQ 表达式。 通过插入对“AsEnumerable”、“AsAsyncEnumerable”、“ToList”的调用来显式评估客户端 - LINQ expression could not be translated. client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList' EF Core 6 - 无法翻译 Linq 表达式。 试图检查链接属性的详细信息 - EF Core 6 - The Linq Expression could not be translated. Trying to check details of linked property
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM