实体框架核心为一对多关系生成两个选择查询

时间:2017-04-18 12:24:18

标签: entity-framework-core

我正在为Google Spanner数据库构建一个EF Core提供程序。在尝试选择一对多关系的实体时,我遇到了一个问题。

例如,假设我有以下实体:

public class Player
{
    public string PlayerId { get; set;}

    public string Name { get; set;}

    public List<Game> Games { get; set;}

}

public class Game
{
    public string GameId { get; set; }

    public string PlayerId { get; set; }
    public Player Player { get; set;}
}

每个游戏都与一个玩家有关,每个玩家都有很多游戏......

运行以下查询时:

ctx.Players
.Include(p => p.Games)
.Where(p => p.PlayerId == "123")
.Select(p => new {
    PlayerId = p.PlayerId,
    Games = p.Games
});

构建两个选择查询并分别针对DB执行:

SELECT "p"."PlayerId" FROM "Players" AS "p" WHERE "p"."PlayerId" = '123'
SELECT "p0"."GameId" FROM "Games" AS "p0" WHERE '123' = "p0"."PlayerId"

这是一个已知问题吗?我是否可以将 SelectExpression 控制为仅作为一个选择创建(使用加入...)?

0 个答案:

没有答案