dotnet / EntityFramework.Docs

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

Docs seting up people to fail #2103

Open hrvoje-grabusic opened 4 years ago

hrvoje-grabusic commented 4 years ago

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.

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.

ajcvickers commented 4 years ago

@hrvoje-grabusic Thanks for the feedback. I'll look into this while updating the docs.