-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ThenInclude with Select unexpected behavior #32796
Comments
this is query we get: DbSet<Request>()
.Include(r => r.Category)
.ThenInclude(c => c.ParentCategory)
.Where(r => r.Category.IsActive && r.Category.ParentCategoryId.HasValue)
.GroupBy(r => r.Category)
.Select(g => new ResultGroupByCategoryQuery{
Category = g.Key,
Parent = g.Key.ParentCategory
}
) nav expansion converts it to: DbSet<Request>()
.Join(
inner: DbSet<Category>(),
outerKeySelector: r => EF.Property<Guid?>(r, "CategoryId"),
innerKeySelector: c => EF.Property<Guid?>(c, "CategoryId"),
resultSelector: (o, i) => new TransparentIdentifier<Request, Category>(
Outer = o,
Inner = i
))
.Where(r => r.Inner.IsActive && r.Inner.ParentCategoryId.HasValue)
.GroupBy(r => r.Inner)
.Select(g => new ResultGroupByCategoryQuery{
Category = g.Key,
Parent = g.Key.ParentCategory
}
) note that this results in the following translation: ShapedQueryExpression:
QueryExpression:
Client Projections:
0 -> Dictionary<IProperty, int> { [Property: Category.CategoryId (Guid) Required PK AfterSave:Throw ValueGenerated.OnAdd, 0], [Property: Category.IsActive (bool) Required, 1], [Property: Category.Name (string), 2], [Property: Category.ParentCategoryId (Guid?) FK Index, 3] }
SELECT c.CategoryId, c.IsActive, c.Name, c.ParentCategoryId
FROM Requests AS r
INNER JOIN Categories AS c ON r.CategoryId == c.CategoryId
WHERE c.IsActive && c.ParentCategoryId IS NOT NULL
GROUP BY c.CategoryId, c.IsActive, c.Name, c.ParentCategoryId
ShaperExpression: new ResultGroupByCategoryQuery{
Category = StructuralTypeShaperExpression:
Category
ValueBufferExpression:
ProjectionBindingExpression: 0
IsNullable: False
,
Parent = StructuralTypeShaperExpression:
Category
ValueBufferExpression:
ProjectionBindingExpression: 0
IsNullable: False
== default(Category) ? null : StructuralTypeShaperExpression:
Category
ValueBufferExpression:
ProjectionBindingExpression: 0
IsNullable: False
.ParentCategory
} we just project category entity and try to access ParentCategory on the client, which is obviously always null. |
duplicate of #29014 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Evidence
Repo
https://github.com/daniel18acevedo/efcore-then-include-select-issue
Include stack traces
Include provider and version information
EF Core version: 7.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET 6.0
Operating system: Windows
IDE: Visual Studio 2022 17.4
The text was updated successfully, but these errors were encountered: