Hi there,
I'm writing my own workflow persistence service to support another database. I have following two save methods to override in my service:
SaveCompletedContextActivity(Activity root)
SaveWorkflowInstanceState(Activity root, bool unlock)
The question is quite simple, how do I find in these two methods when I need to INSERT workflow record in database and when I need to UPDATE workflow record in database
I can't find any boolean flags on Activity object indicating that this instance was already persisted.

WorkflowPersistence simple question
Arnar Vilhjálmsson
efontana
The primary key in your table should be the InstanceId. Then you just need to check if there is already an entry with that value. If there is you UPDATE and if not you INSERT. To get the InstanceId from the Activity you can do the following in your persistence service:
Guid contextGuid = (Guid)rootActivity.GetValue(Activity.ActivityContextGuidProperty);
Tim Noonan MSFT
Looks like I've found a good solution... Just need a confirmation from MS guys...
public class MyPersistenceService : WorkflowPersistenceService
{
private static DependencyProperty LoadedProperty = DependencyProperty.RegisterAttached("Loaded", typeof(bool), typeof(MyPersistenceService), new PropertyMetadata(DependencyPropertyOptions.NonSerialized));
... After load & save:
rootActivity.SetValue(LoadedProperty, true);
... Before save:
if ((bool)rootActivity.GetValue(LoadedProperty))
UpdateObject();
else
InsertObject();
}
Thank you, Lutz
Mike Hernandez - MSFT
I can't afford to double network traffic with each update of the workflow making additional select...
Is there any possibilities to label a root activity I may label it after loading from DB, and then check the presence of this label while saving, thus deciding to INSERT xor UPDATE...
I tried to use UserData dictionary, but it is somehow shared between instances...
Any help
Mario Delamboy
I use data access layer that hides database from me. I work with data objects which know how to create/load/save them. So no, a stored procedure is no-go.
There should be some Tag property or something like this to label workflow instance. I can use dictionary, but I don't like the idea, that it will only grow in size and cleaning this dictionary is an additional work.
So my beauty taste is saying me - the right place to label a workflow is a workflow itself. I'd probably subclass both branches (Sequential & StateMachine) and add a private field, that i'll set after WF it loaded from database...
Or maybe there is a workaround without subclassing