我理解为什么 EF 有 ToListAsync
或 SaveChangesAsync
- 因为它等待数据库操作执行。但是 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.
关于c# - 为什么 Entity Framework 有 AddAsync?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53082194/