Entity Framework Core generates two one-to-many selection queries

I am creating an EF Core provider for db Google Spanner. I ran into a problem while trying to select an object with a ratio of one to large .

For example, suppose I have the following objects:

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 associated with one player, and each player has many games ...

When executing the following query:

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

Two selection queries are created and executed separately from the database:

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

Is this a known issue? Can I control SelectExpression , which will be created only as one of them (using union ...)?

0
source share

Source: https://habr.com/ru/post/1686586/


All Articles