问题
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