Entity Framework Core generates two select queries for one-to-many relationship

大憨熊 提交于 2020-01-05 04:28:08

问题


I'm building an EF Core provider for the Google Spanner db. I've bumped with an issue when trying to select an entity with one to many relationship.

For example, lets say I have the following entities:

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;}
}

Each Game is related to one Player and each Player has many games...

When running the following query:

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

Two select queries are constructed and executed separately against the DB:

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

Is it a known issue? Can I control the SelectExpression to be created only as one select (using join...)?

来源:https://stackoverflow.com/questions/43472071/entity-framework-core-generates-two-select-queries-for-one-to-many-relationship

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!