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

Expose StateManager.TryGetEntry in DbContext.ChangeTracker #33003

Closed
jamezamm opened this issue Feb 5, 2024 · 5 comments
Closed

Expose StateManager.TryGetEntry in DbContext.ChangeTracker #33003

jamezamm opened this issue Feb 5, 2024 · 5 comments

Comments

@jamezamm
Copy link

jamezamm commented Feb 5, 2024

From DbContext.ChangeTracker, the only way to find a tracked entity by its primary key is to iterate over ChangeTracker.Entries().

Since this is not efficient, I propose exposing StateManager.TryGetEntry in DbContext.ChangeTracker (Ex: ChangeTracker.FindEntry). DbSet().Find() already employs this method to locate a tracked entity by key.

Hopefully this won't be too much effort because StateManager is already utilized in the ChangeTracker class, like StateManager.Entries().

@ErikEJ
Copy link
Contributor

ErikEJ commented Feb 5, 2024

@jamezamm
Copy link
Author

jamezamm commented Feb 5, 2024

Since a bug (which should be fixed by 8.0.2) is preventing me from switching to EF8, I did not realise this had been implemented on DbSet().Local.

Has this been implemented on DbContext.ChangeTracker?

@ajcvickers
Copy link
Contributor

Duplicate of #29685

@ajcvickers ajcvickers marked this as a duplicate of #29685 Feb 5, 2024
@jamezamm
Copy link
Author

jamezamm commented Feb 5, 2024

In my case I am working with an object that can be of any type, thus I do not know the specific type at design time.

Although DbSet().Local.FindEntry is a good feature, I would still have to access it via reflection.

For that reason I suggested to include StateManager.TryGetEntry (as FindEntry) in DbContext.ChangeTracker.

In my opinion, this is an enhancement to #29685 rather than a duplicate.

@ajcvickers
Copy link
Contributor

@jamezamm Non-generic access is covered by #21066.

@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Feb 14, 2024
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

3 participants