First of i love EF and recommend it to everyone but the docs about relations are setting people up to fail.
Under the section adding a related enitity the query loads all the posts only to insert one more into the database.
using (var context = new BloggingContext())
{
var blog = context.Blogs.Include(b => b.Posts).First();
var post = new Post { Title = "Intro to EF Core" };
blog.Posts.Add(post);
context.SaveChanges();
}
If the documentation is going to teach people worst practices then it needs to educate about the problem and how to overcome it.
I get that the motivation is to show EF makes data access code simple and object oriented but this in this case it is misleading potential new user that this code is just fine and there is no need to do it any other way and the problem in their apps will show only in a year.
I expect the official documentation to teach new user about performance traps like this and how to avoid them and not be a primary source of performance traps.
The above code is the perfect place to explain that the object oriented example is not recommended when there will be a lot of content and give an example of inserting by assigning an ID.
There seems to be a whole ecosystem of people who hate EF and ORMs because they got burned by assumptions about how easy it is do things the object oriented way and i think the official docs should not setup people to get burned.
This issue tracker is for documentation
For product issues, use https://github.com/aspnet/EntityFramework/issues
Hi,
First of i love EF and recommend it to everyone but the docs about relations are setting people up to fail.
Under the section adding a related enitity the query loads all the posts only to insert one more into the database.
If the documentation is going to teach people worst practices then it needs to educate about the problem and how to overcome it.
I get that the motivation is to show EF makes data access code simple and object oriented but this in this case it is misleading potential new user that this code is just fine and there is no need to do it any other way and the problem in their apps will show only in a year.
I expect the official documentation to teach new user about performance traps like this and how to avoid them and not be a primary source of performance traps.
The above code is the perfect place to explain that the object oriented example is not recommended when there will be a lot of content and give an example of inserting by assigning an ID.
There seems to be a whole ecosystem of people who hate EF and ORMs because they got burned by assumptions about how easy it is do things the object oriented way and i think the official docs should not setup people to get burned.