简体   繁体   English

在Workflow Foundation 4中管理ObjectContext

[英]Managing ObjectContext in Workflow Foundation 4

I'm working with Workflow Foundation 4 and Entity Framework 4.1. 我正在使用Workflow Foundation 4和Entity Framework 4.1。

I am building my workflow with sets of ReceiveAndSendReply activities. 我正在使用ReceiveAndSendReply活动集构建我的工作流。 It makes sense to me to use a single ObjectContext (or DbContext, now) per set of receive and send reply activities. 对我来说,每组接收和发送回复活动都使用一个ObjectContext(或现在的DbContext)对我来说很有意义。

How should I manage the ObjectContext? 我应该如何管理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 . 就像这篇文章一样,我们使用自定义服务行为和GetExtension

Beware, though: If your workflow has a persistence point, implicit or explicit, you cannot expect the Context to survive this! 但是要当心:如果您的工作流具有隐式或显式的持久性点,则您不能指望Context能够幸免于此!

Its better not to use a DbContext or an ObjectContect directely in your worklfow. 最好不要在工作流中直接使用DbContext或ObjectContect。 Put these in a workflow extension and let those load POCO entoties for you. 将它们放在工作流扩展中,然后让它们为您加载POCO实体。 Make sure you only use POCO entities in your worklfow and that they are marked as serializable. 确保仅在工作流程中使用POCO实体,并且将其标记为可序列化的。 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. 而且,即使您现在不需要持久性,也最好以正确的方式进行将来的开发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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