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

纵然是瞬间 提交于 2020-03-17 06:57:39

问题


I could not find any info on this anywhere.

There are ToListAsync(), AddAsync() and more, but could not find any documentation about UpdateAsync() or RemoveAsync().

Does anyone know anything about this?


回答1:


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.



来源:https://stackoverflow.com/questions/42034282/are-there-dbset-updateasync-and-removeasync-in-net-core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!