Note that there are some explanatory texts on larger screens.

plurals
  1. POWF4 TransactionScope containing several custom activities with EF4 database updates
    primarykey
    data
    text
    <p>I have created several custom activities that update tables in my DB (in this case SQL Server Compact), using Entity Framework 4 with POCOs. </p> <p>If I put more than one of these inside a WF4 TransactionScope activity, I'm running into problems: EF disposes the DB connection after the first activity has finished, and when the next DB activity tries to do a DB update a new connection is built up. At this moment an exception is thrown.</p> <pre><code>System.Activities.WorkflowApplicationAbortedException : The workflow has been aborted. ----&gt; System.Data.EntityException : The underlying provider failed on Open. ----&gt; System.InvalidOperationException : The connection object can not be enlisted in transaction scope. </code></pre> <p>Do I have to keep the EF connection open during the whole transaction scope? How can I do that? Create an explicit custom activity for that, or is there a standard way?</p> <p><strong>My current workaround</strong> goes like this: I created a new code activity that creates our ObjectContext and explicitely calls dbContext.Connection.Open(). It returns the ObjectContext, which is then saved in a workflow variable. That one is passed to all the DB related activities as an InArgument&lt;>. Inside my DB activities, I use this ObjectContext if it is passed in, otherwise I create a new one.</p> <p>This does work, but I'm not satisfied with this solution: It needs the new InArgument for every DB related activity. In the workflow designer, I have to insert that special OpenDatabaseConnection activity inside the transaction scope, and then make sure that the correct variable is passed into all DB activities. This seems to be very inelegant and error prone, especially if other team members have to use these DB activities.</p> <p>What would be a better way to handle this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload