PetaPoco Transaction in Multithread Env

南楼画角 提交于 2019-12-01 05:15:35

Yes, you need a separate PetaPoco Database instance per-thread. See this quote from the PetaPoco documentation:

Note: for transactions to work, all operations need to use the same instance of the PetaPoco database object. So you'll probably want to use a per-http request, or per-thread IOC container to serve up a shared instance of this object. Personally StructureMap is my favourite for this.

I bolded the phrase that gives the clue. It is saying that one instance of the PetaPoco database object should be used per-thread.

Hi use with nolock in select query because the table may be locked. long count = db.ExecuteScalar("SELECT Count(*) with nolock FROM MediaDevices");

sorry dude.. yes you are right. they change the object to be null. so you cannot use the same object to threading. you have to use they use described like db=GetDataBase() ; db2=GetDataBase();

otherwise you can change the source code for your requirement. i think their license allow it. but i am not sure.

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