-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Broken code for saving a graph of entities #4863
Comments
I tried to reproduce this, and I initially received the following error
This occurs because I created a new project with Nullable reference types enabled. Reading the comment "this generates compilator warnings", I expect this is also the case for you. To fix the example, either remove the using (var context = new BloggingContext())
{
var blog = new Blog
{
Url = "http://blogs.msdn.com/dotnet",
Posts = new List<Post>
{
new Post { Title = "Intro to C#", Content = string.Empty},
new Post { Title = "Intro to VB.NET", Content = ""},
new Post { Title = "Intro to F#", Content = "Intro to F#"},
}
};
context.Blogs.Add(blog);
context.SaveChanges();
} If wanted, I can update the docs by assigning a value to the content properties. |
The primary issue is rather that there is no clarification what happens with the |
@litoj it's normal that the entity has id |
Yes, but how does the |
Sorry @litoj , I don't know - normally, that should also work automatically. |
Type of issue
Code doesn't work
Description
I am trying to save a graph just like in the example shown. But there are multiple issues with the example:
Post
, because the executedINSERT
has stillBlogId=0
Page URL
https://learn.microsoft.com/en-us/ef/core/saving/related-data#adding-a-graph-of-new-entities
Content source URL
https://github.com/dotnet/EntityFramework.Docs/blob/main/entity-framework/core/saving/related-data.md
Document Version Independent Id
c7517e7d-f011-a24c-53da-913771913998
Article author
@ajcvickers
The text was updated successfully, but these errors were encountered: