Coldairarrow / EFCore.Sharding

Database Sharding For EFCore
Apache License 2.0
694 stars 144 forks source link

并行操作数据库时会有问题 #96

Closed wsiscool closed 3 years ago

wsiscool commented 3 years ago

如题,场景是在队列消费时,因为同时会有多个消费异步执行,但是看IShardingDbAccessor容器注入的是作用域,导致了并行执行时会抛出异常导致消费失败,异常信息:This MySqlConnection is already in use,能否将IShardingDbAccessor的注入方式以配置的形式开放出来

Coldairarrow commented 3 years ago

自己创建scope啊

wsiscool commented 3 years ago

IShardingDbAccessord的实现ShardingDbAccessor我看是internal,没办法自己创建

wsiscool commented 3 years ago

问题已解决,理解错意思了,Coldairarrow 所说的自己创建scope的意思是,使用IServiceScopeFactory来CreateScope,使得自定义的作用域内都是独立的,就解决这个问题

Coldairarrow commented 3 years ago

是的