efcore
efcore copied to clipboard
Using AsSplitQuery with AsNoTracking causes duplicated Included entities
File a bug
Remember:
When using AsSplitQuery with AsNoTracking in a many to many or many to one relationship, I end up with multiple duplicated children entities (by Key). My hypothesis is that as we are having many queries with no ChangeTracker, it's adding it by duplicate. If I only use one of them, it works flawlessly.
Workaround:
- I'll use only AsSplitQuery to avoid the Cartesian Explosion.
Include your code
context.ParentEntity
.Include(pe => pe.ChildrenEntities)
.AsSplitQuery()
.AsNoTracking()
.ToList()
ParentEntity (Id, Name, ChildrenId)
1, "First", 1
2, "Second", 2
3, "Third", 1
4, "Forth", 2
ChildrenEntity (Id, Name)
1, "First"
2, "Second"
Include stack traces
Include provider and version information
EF Core version: 6.07 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: dotnet 6.0 Operating system: Windows 10 IDE: Visual Studio 2022
This issue is lacking enough information for us to effectively reproduce. Please post a runnable project/solution or complete code listing that demonstrates the behavior you are seeing.
EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.
BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.