Skip to content

Update Attach docs to reference cascade delete/delete orphans timing #26718

Closed

Description

Use State to set the state of only a single entity.

Am I right in thinking this no longer happens due to the cascade changes? It appears so in my code.

I have 2 related entities, one is read from the DB, the other is attached, updated, saved and then detached. What I find is that this removes both entities from the change tracker such that subsequent updates to the original DB-sourced entity do not get saved back to the DB on subsequent calls to SaveChanges..

I see changetracker.DebugView.LongView get cleared when calling dbEntry.State = EntityState.Detached; on the object I set the State of, ie it clears the related entities that were already present. This means the docs are wrong - setting State adds the object to the change tracker and links it into the graph of related entities (whether directly or indirectly).

I think the docs were intended to be the correct behaviour.

Note that I add the entity to the change tracker by setting dbEntry.State = EntityState.Unchanged and not using the ChangeTracker.Attach() method, as per the docs, deliberately to affect this 1 entity independantly.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions