PetaPoco Transaction in Multithread Env

前端 未结 3 1537
旧时难觅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.

提交回复
热议问题