问题
I'm working with Workflow Foundation 4 and Entity Framework 4.1.
I am building my workflow with sets of ReceiveAndSendReply activities. It makes sense to me to use a single ObjectContext (or DbContext, now) per set of receive and send reply activities.
How should I manage the ObjectContext? Are there activities just for this or do I need to manually manage it?
回答1:
Its better not to use a DbContext or an ObjectContect directely in your worklfow. Put these in a workflow extension and let those load POCO entoties for you. Make sure you only use POCO entities in your worklfow and that they are marked as serializable. Doing it another way will certainly cause problems with workflow persistence and long running workflows. And even if you don't need persistence now it is better to do it the right way for any future development.
回答2:
No, there are no built-in activities for this.
We do it with a custom service behavior and GetExtension
, like in this post.
Beware, though: If your workflow has a persistence point, implicit or explicit, you cannot expect the Context to survive this!
来源:https://stackoverflow.com/questions/6097786/managing-objectcontext-in-workflow-foundation-4