Document 'Disconnected Entities' - The code example in the Handling Deletes section works unexpected
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
- Issue type
- Documentation
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- csharp
- Domain
- documentation
Research direction
Start in the documentation's “Handling Deletes” section and review the graph-diff example using integer primary keys. Verify the behavior with an aggregate containing multiple new posts, then update the wording or example to account for multiple entities whose IDs are zero. Done means the documented example no longer implies that all new posts compare as the same entity.
Written by the indexing model from the issue text.
Description
This issue tracker is for documentation
Hi,
In the section 'Handling Deletes' there is a code example for handling true deletes using a graph diff. However I noticed that (at least for me) it worked unexpected when u are using integer PK's. For example when you send an aggregate like blog with 3 new posts. the posts are new and so the Id = 0. The first post gets added like expected but the next ones are not because now there is already one with id=0 so those posts are not added.
This behavior is caused by the following lines:
`var existingPost = existingBlog.Posts
.FirstOrDefault(p => p.PostId == post.PostId);
if (existingPost == null)
{
existingBlog.Posts.Add(post);
}
else
{
context.Entry(existingPost).CurrentValues.SetValues(post);
}`
For me it works expected when I change it to:
var existingPost = existingBlog.Posts
.FirstOrDefault(p => p.PostId == post.PostId && p.PostId != 0)
Perhaps this should be mentioned in the docs or the example updated?
- Dominant language
- Mermaid
- Stars
- 1.7k
- Forks
- 2k
- Avg merge
- 7d 23h
- Merged PRs (30d)
- 16
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/EntityFramework.Docs
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
dotnet/EntityFramework.Docs#5455 ·
-
Difficulty 2/5 Half a day Newbie friendliness 72/100
dotnet/EntityFramework.Docs#4774 ·
-
area-change-tracking area-model-building
Difficulty 1/5 Under an hour Newbie friendliness 65/100
dotnet/EntityFramework.Docs#4278 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
dotnet/EntityFramework.Docs#4100 · 1 comment ·
-
area-tools
Difficulty 1/5 Under an hour Newbie friendliness 62/100
dotnet/EntityFramework.Docs#3927 · 1 comment ·
All issues in dotnet/EntityFramework.Docs
Similar issues
-
user-reported
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Kong/developer.konghq.com#7316 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
bug triage:deciding
Difficulty 1/5 Under an hour Newbie friendliness 88/100
open-telemetry/otel-arrow#4132 ·
-
Ecosystem: ClawMetry — the Qwen Code reader is now free and open source (follow-up to #9294 / #9338) Opencategory/integration priority/P3 scope/documentation status/ready-for-human type/feature-request
Difficulty 1/5 Under an hour Newbie friendliness 84/100