State of join entity entry is "Added" although entity is tracked by setting State="Modified". #28005
Labels
area-change-tracking
blocked
customer-reported
punted-for-7.0
Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints.
punted-for-8.0
Originally planned for the EF Core 8.0 (EF8) release, but moved out due to resource constraints.
type-bug
Milestone
After updating from EF Core 5 to EF Core 6, some of our unit tests failed. I couldn't figure out by which of the known breaking changes this might be caused, but found the changed behavior in a method that uses stubs to remove an entry from a many-to-many relation. In EF Core 5, the state of the join entity entry changes from
Added
toDeleted
, while in EF Core 6, it changes fromAdded
toDetached
. (The "new" behavior seems to be "more correct".) As I tried to solve our remove-problem, I wondered:Why is the state of the join entity entry
Added
at all?odd behavior
The involved stubs are only made tracked in
Unchanged
orModified
state. But the state of the join entity entry isUnchanged
orAdded
. Particularly strange: Whether it isUnchanged
orAdded
depends on the order in which the involved stubs are made tracked or whether a stub is first madeUnchanged
and thenModified
right after.In the following code, these three cases are covered (see
foreach
andswitch
). Furthermore, the code contains tables showing the state of the join entity entry and the final result for each of these three cases, both for EF Core 5 and EF Core 6.Is there a "good reason" for the way these three cases behave, and that not all behave the same?
runnable code
console output
provider and version information
EF Core version: 6.0.5
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system: Windows 11
IDE: Visual Studio 2022 17.1.6
The text was updated successfully, but these errors were encountered: