Search code examples
asp.networkflow-foundation-4

WF Persistense and Database Access


I am very new to WF and trying to learn it. I know the basics of WF right. Hopefully i will make my problem clear.

But I am facing a problem. I am developing a demo application to prove the power of WF to my team.

Now I know how to unload a workflow and then resume the same using bookmarks.

Now I am doing an ASP.NET App. What it does is -

  1. Get the Empname and Age.
  2. Start the workflow and pass the data.
  3. An activity will take this data and save it to the database (Employee database) for eg the row in database is like

[

Id      EmpName   Age   Status   WorkflowInstance

1         blah    24    False     {Guid of WorkflowInstanceId}

]

  1. Then next activity in sequence will bookmark and unload the workflow from memory.
  2. I did the steps 1 to 4 to add 10 employee with status - "False".
  3. I can see 10 workflow instances persisted in the WorkflowInstanceSchema and they are all unloaded.
  4. Now before resuming each workflow I want someone to login. He will see the list of all the Workflow instance in a GridView with a checkbox to select multiple records in the grid.

  5. From the grid the user will select rows and approve and pass a status "Y" for the selected workflow and load the workflow again back in memory and pass in the input and resume from the bookmark. Then the workflow completes.

[Now my question is that in the grid I am doing a query to the Employee database using EF and get the Employee data in database.]

Is this the only way to get the data, because here is no workflow involved in my query to my database. This is like we would normally do in any applications that we are developing for many years. Then what does workflow has to offer in this case.

What i think might be another way is - Should i use the Tracking services and custom data to the every Workflow. and then query that data. But this will duplicate things as now I have employee data in my database and also in TrackingStore.

How should i handle this issue.

Any guidance on the same is really apreciated. Meanwhile I am continously learning to realize the real power of WF and trying to figure out whats the right way.


Solution

  • The workflow instance store is not the place where you want to keep your transactional or queryable data. I like to think of it as the place to store data that supports the process. If you need access to this data from outside the workflow for listing in a single view (like your grid) then you should really store it outside the workflow instance store. You do not want to be resuming all your workflows just to get the data from each so you can display them all in a single view. If however the data in your workflow is only for that process, not visible from outside the workflow and is in an invalid state until the process reaches a given point, then I would keep it in the workflow data until it is ready for the transactional system.

    You could use workflow's promoted properties as a solution to this but I would advise against it. You want to own the schema of your transactional data. Workflow is just the place that you implement the state machine for this process.

    We often use tracking for this type of business data extraction but if you own the workflow I would suggest using an explicit activity to save this data to your own tables. At least then it would be obvious where you are doing this in your process, rather than it being some magic that happens in the workflow host.