Are there DBSet.UpdateAsync() and RemoveAsync() in .net core?

前端 未结 1 2007
暖寄归人
暖寄归人 2021-02-03 21:26

I could not find any info on this anywhere.

There are ToListAsync(), AddAsync() and more, but could not find any documentation about Upd

1条回答
  •  孤独总比滥情好
    2021-02-03 22:07

    ToListAsync exists because it actually causes EF to head off to the data store to retrieve the data. This may take some time, hence why you can call it asynchronously.

    AddAsync however, only begins tracking an entity but won't actually send any changes to the database until you call SaveChanges or SaveChangesAsync. You shouldn't really be using this method unless you know what you're doing. The reason the async version of this method exists is explained in the docs:

    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.

    Update and Remove are the same as Add in as much as they only affect the internal tracking until you save the changes you've made.

    0 讨论(0)
提交回复
热议问题