简体   繁体   中英

Managing ObjectContext in Workflow Foundation 4

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?

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM