dotnet / EntityFramework.Docs

Documentation for Entity Framework Core and Entity Framework 6
https://docs.microsoft.com/ef/
Creative Commons Attribution 4.0 International
1.56k stars 1.94k forks source link

"Update" code sample is really Add #4684

Closed BrendaSplenda closed 1 month ago

BrendaSplenda commented 2 months ago

Type of issue

Other (describe below)

Description

Regarding the following code sample:

// Update
Console.WriteLine("Updating the blog and adding a post");
blog.Url = "https://devblogs.microsoft.com/dotnet";
blog.Posts.Add(
    new Post { Title = "Hello World", Content = "I wrote an app using EF Core!" });
db.SaveChanges();

This is really an "Add" operation, not "Update". The comment perhaps needs an adjustment or clarification. Thank You!

Page URL

https://learn.microsoft.com/en-us/ef/core/get-started/overview/first-app?source=recommendations&tabs=netcore-cli

Content source URL

https://github.com/dotnet/EntityFramework.Docs/blob/main/entity-framework/core/get-started/overview/first-app.md

Document Version Independent Id

b38b9d14-6bad-12e0-8d2d-24b50bc4977e

Article author

@Rick-Anderson

ajcvickers commented 2 months ago

@BrendaSplenda From a relational perspective, the code is showing EF making both an UPDATE and an INSERT when SaveChanges is called. In terms of the comment, it refers to generally "updating" (i.e. "changing") the object graph and then letting EF work out the updates needed.

BrendaSplenda commented 1 month ago

@ajcvickers, thanks for your reply. I suggest putting that very explanation in the documentation, as otherwise the "update" title will confuse newbies. (If they weren't newbies, they probably wouldn't need the documentation to begin with.)