-
Notifications
You must be signed in to change notification settings - Fork 3.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
Support AddAsync && AddRangeAsync #2291
Comments
Good question! Sorry we left the details out of the notes. The removal of Our understanding of how to best apply the Task-based async pattern to API designs is still somewhat evolving. Despite how powerful the support for async programming is in C#, synchronous APIs are still easier to use correctly in many circumstances. In particular, it is hard to use async APIs correctly when from synchronous code 😄 In principle we create async versions of APIs to enable server applications to scale better by saving threads that would otherwise be wasted waiting for I/O operations to be completed. Following that principle we originally introduced
Suddenly async had become “viral”: any time you use It just looked like a slippery slope in which we would end up making our API much more complex in exchange for very little value. (After all, correctly implemented value generators should not be chatty on the network. E.g. we use a default value block size of 10, meaning that only once every ten calls to Another way to approach the problem is shown in the Stream class, in which you can call |
Note for triage: After thinking about this again while writing the explanation above I came to the conclusion that it would make sense to bring back That said, this doesn't seem to be high enough priority to do it in the EF 7.0.0 release so we can either move the issue to the backlog or close it and wait for additional feedback. |
TLDR; Thanks @divega for your detailed explanation! I understand your concerns about async having "viral" characteristics. To my knowledge there are 2 scenarios were value generation kicks in: - Calling
|
Note, that it is not necessary to make everything async from an efficiency standpoint. It is totally OK to use EF mostly synchronously and only make time-consuming queries async. Async does not make operations any faster, it merely saves a thread while the IO is running. The thread saving benefit is proportional to the time that the async operation takes. Your reasoning is correct: Not all APIs must be async from an efficiency standpoint. |
Be sure to update and reenable the test from #5254 when this is done. |
If EF7 is configured with GenerateValueOnAdd(true), sql server sequences are used, and so every time Add(entity) is called, EF7 will send a query to the store so that it can assign a new key to the entity.
I remember I have seen AddAsync && AddRangeAsync overloads in previous Ef7 releases. Why did you remove them?
I found some notes here: https://github.com/aspnet/EntityFramework/wiki/Design-Meeting-Notes:-January-16,-2015 ("Update: we decided to remove AddAsync entirely") but i could not find any reasoning for this change.
The text was updated successfully, but these errors were encountered: