Skip to content
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

Detect Changes - Incorrect State #13565

Closed
avinash-phaniraj-readify opened this issue Oct 10, 2018 · 1 comment
Closed

Detect Changes - Incorrect State #13565

avinash-phaniraj-readify opened this issue Oct 10, 2018 · 1 comment

Comments

@avinash-phaniraj-readify

Scenario -

  1. Attach an entity to the context with a known primary key specified (Id > 0)
  2. Extend entity graph by adding/associating another entity with an Id > 0
  3. Trigger DetectChanges for ex; invoke context.ChangeTracker.Entries().

You will find the new entity (which was not explicitly attached) being tracked.
It's state however is incorrectly tracked as "Added" and not "Unchanged".

If the new entity were to be attached via context.Attach, its state is correctly determined.

Steps to reproduce

Repro : https://github.com/avinash-phaniraj-readify/EFCoreTestBed/tree/DetectChangesStateError

           var context = new TestDbContext(options);

            var emp = new Employee { Id = 1, Name = "known employee" };
            emp.Devices = new List<EmployeeDevice>();
            context.Attach(emp);

            var device = new EmployeeDevice { Id = 1, EmployeeId = 1, Device = "known device" };

            emp.Devices.Add(device);
            context.ChangeTracker.Entries();

            Debug.Assert(context.Entry(device).State == EntityState.Unchanged);

Further technical details

EF Core version: 2.1.4
Database Provider: EntityFrameworkCore.SqlServerCompact35 2.1.2.1
Operating system: Win 10
IDE: (e.g. Visual Studio 2017 15.8.4)

@ajcvickers
Copy link
Contributor

@avinash-phaniraj-readify Please see my response to #13564 and also see #13575 which would change this if we chose to implement it.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants