gpt4 book ai didi

c# - 为什么 Entity Framework 有 AddAsync?

转载 作者:太空狗 更新时间:2023-10-29 20:09:17 28 4
gpt4 key购买 nike

我理解为什么 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com