在 Workflow Foundation 4 中管理 ObjectContext
我正在使用 Workflow Foundation 4 和 Entity Framework 4.1。
我正在使用一组 ReceiveAndSendReply 活动构建我的工作流程。对我来说,每组接收和发送回复活动使用一个 ObjectContext(或现在的 DbContext)是有意义的。
我应该如何管理 ObjectContext?是否有专门用于此目的的活动,或者我需要手动管理它?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,没有为此目的的内置活动。
我们使用自定义服务行为和
GetExtension
来完成此操作,例如 this发布。但请注意:如果您的工作流程有一个隐式或显式的持久点,您就不能指望上下文能够幸免于难!
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!
最好不要在工作流中直接使用 DbContext 或 ObjectContect。将它们放入工作流程扩展中,让它们为您加载 POCO 实体。确保您仅在工作流中使用 POCO 实体,并且它们被标记为可序列化。如果采用另一种方式,肯定会导致工作流持久性和长时间运行的工作流出现问题。即使你现在不需要坚持,最好还是以正确的方式去做,以适应未来的发展。
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.