PetaPoco Transaction in Multithread Env

前端 未结 3 1467
旧时难觅i
旧时难觅i 2021-01-12 17:41

I just test PetaPoco Transaction in a multithread way...

I have a simple test case :

-- Simple value object call it MediaDevice -- Insert a record an update

相关标签:
3条回答
  • 2021-01-12 18:18

    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.

    0 讨论(0)
  • 2021-01-12 18:20

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

    0 讨论(0)
  • 2021-01-12 18:28

    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.

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