views:

98

answers:

1

I'm trying to get my head round WF. I'm visualizing a State Machine Workflow with long-running workflows that will be stored in using the SQL persistence service.

A user may have more than one outstanding workflows assigned. I can't work out two things.

  1. How do I get a list of all outstanding workflows?
  2. How do I get a list of workflows for a particular user?

Do I have to unpersist (there's gotta be a better word than that) each and iterate through them or am I missing something?

+2  A: 

You have more than one option for that question.

A workflow itself has no relationship to your user. Because WorkflowFoundation doesn't know what is your workflow about at all. So you must provide additional information to get the workflows for your users back from the database.

First option would be to use the WF Tracking feature to store the associated user as one of the first steps in your running workflow in the tracking database. So you can later query the SQL database for all workflow instance ids that have such tracking records with the specified user attached.

Second option would be to extend the database with a custom table that holds the relationship between your users and the running workflow ids. This table would be filled in case of a new workflow started for a user and the associated record must be cleared out when the workflow ends or gets an exception while running.

Mischa
I need to do some reading to understand what you meant by the first option. For the second option, would you suggest extendng the SQL persistence service or just having a custom activity to write out to a separate table?
serialhobbyist
For the first option you can use the TrackData method in an activity to write key/value pairs to the database.For writing your own tables I would go the custom activity route.
Mischa
Okay, thanks a lot for your replies.
serialhobbyist