Managing ObjectContext in Workflow Foundation 4

我们两清 提交于 2019-12-24 00:48:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!