c# - 为什么 Entity Framework 有 AddAsync?

标签 c# .net entity-framework entity-framework-core

我理解为什么 EF 有 ToListAsyncSaveChangesAsync - 因为它等待数据库操作执行。但是 AddAsync 只返回 Task.FromResult - 那么为什么会有 AddAsync 方法呢?我为什么要使用它?

最佳答案

来自documentation :

This method is async only to allow special value generators, such as the one used by 'Microsoft.EntityFrameworkCore.Metadata.SqlServerValueGenerationStrategy.SequenceHiLo', to access the database asynchronously. For all other cases the non async method should be used.

SqlServerValueGenerationStrategy.SequenceHiLo :

A sequence-based hi-lo pattern where blocks of IDs are allocated from the server and used client-side for generating keys.

另见 What's the Hi/Lo algorithm?

关于c# - 为什么 Entity Framework 有 AddAsync?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53082194/

相关文章:

.net - 使用带有自定义连接对象的 EF 存储库?

c# - C# 中的 Twitter update_profile_image

c# - 无法从存储过程中获取返回值

c# - 获取当前 XmlReader 位置的 'path'

java - IE 中的 Selenium Hover 元素

c# - @model 关键字在 ASP.NET MVC View 中有什么作用?

entity-framework - 逆向工程数据库上的 EF 5.0 迁移。无法更新模型更改,因为表已存在

c# - 如何将文本字符串从 Base64 解码为字节数组,以及如何在不损坏数据的情况下获取此字节数组的字符串属性

c# - 组件属性不支持复杂的内容(混合的C#和标记)

c# - 进行多次更新时如何避免在 Entity Framework 4 中锁定数据库