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

Provide a hook for identity resolution #20124

Closed
Tracked by #22954
ajcvickers opened this issue Mar 2, 2020 · 2 comments · Fixed by #28246
Closed
Tracked by #22954

Provide a hook for identity resolution #20124

ajcvickers opened this issue Mar 2, 2020 · 2 comments · Fixed by #28246
Assignees
Labels
area-change-tracking closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Milestone

Comments

@ajcvickers
Copy link
Member

In general, identity resolution is a difficult problem. See #20116 (comment) and many other similar comments over the years.

However, maybe we could provide a hook that applications can do to implement their own identity resolution when EF starts tracking a graph. This likely wouldn't cover difficult were merging needs to happen, but simple cases where duplicates can be essentially ignored could become much easier.

@ajcvickers
Copy link
Member Author

Related: identity resolution for no-tracking queries #19877

@cdaragorn
Copy link

I just ran into this problem and would like to promote this proposed solution. In my case I have to take a slower route in order to prevent hitting the same entity multiple times. It would be extremely nice for my case if I could somehow just say "don't worry about conflicts. I know they're ok".

To give some context, I was using FindAsync() to take advantage of already tracked entities but was then using RemoveRange() on a foreign keyed entity which triggers adding the parent entity to tracking. Since I have no control over that it has become impossible for me to use FindAsync() and I now will have to take the slow route to the database for each of those calls.

ajcvickers added a commit that referenced this issue Jun 16, 2022
Part of #626
Fixes #20124

This is essentially a call back that happens when an instance withe the same key as an existing tracked instance is attached. The existing instance is always retained, but the interceptor gets the chance to change property values of the tracked instance. This will typically be used to copy over values from the duplicate instance (i.e. painting from a detached entity) or just skip the duplicate. Interceptor implementations are provided to do these two things.
@ajcvickers ajcvickers modified the milestones: Backlog, 7.0.0 Jun 16, 2022
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jun 16, 2022
@ajcvickers ajcvickers self-assigned this Jun 16, 2022
ajcvickers added a commit that referenced this issue Jun 20, 2022
Part of #626
Fixes #20124

This is essentially a call back that happens when an instance withe the same key as an existing tracked instance is attached. The existing instance is always retained, but the interceptor gets the chance to change property values of the tracked instance. This will typically be used to copy over values from the duplicate instance (i.e. painting from a detached entity) or just skip the duplicate. Interceptor implementations are provided to do these two things.
@ajcvickers ajcvickers modified the milestones: 7.0.0, 7.0.0-preview6 Jun 20, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0-preview6, 7.0.0 Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-change-tracking closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants