I have created an activity to return dataset as below:
public class DbQueryDataSet : AsyncCodeActivity<DataSet>
{
// private variables
IDictionary<string, Argument> parameters;
DbHelper dbHelper;
// public arguments
[DefaultValue(null)]
public InArgument<string> ProviderName { get; set; }
[DefaultValue(null)]
public InArgument<string> ConnectionString { get; set; }
[DefaultValue(null)]
public InArgument<string> ConfigName { get; set; }
[DefaultValue(null)]
public CommandType CommandType { get; set; }
[RequiredArgument]
public InArgument<string> Sql { get; set; }
[DependsOn("Sql")]
[DefaultValue(null)]
public IDictionary<string, Argument> Parameters
{
get
{
if (this.parameters == null)
{
this.parameters = new Dictionary<string, Argument>();
}
return this.parameters;
}
}
/*public DbQueryDataSet()
{
this.CommandType = CommandType.Text;
}*/
protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
{
// configure the helper object to access the database
dbHelper = new DbHelper();
dbHelper.ConnectionString = this.ConnectionString.Get(context);
dbHelper.ProviderName = this.ProviderName.Get(context);
dbHelper.ConfigName = this.ConfigName.Get(context);
dbHelper.Sql = this.Sql.Get(context);
dbHelper.CommandType = this.CommandType;
dbHelper.Parameters = this.parameters;
dbHelper.Init(context);
// create the action for doing the actual work
Func<DataSet> action = () => dbHelper.GetDataSet();
context.UserState = action;
return action.BeginInvoke(callback, state);
}
protected override DataSet EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
{
Func<DataSet> action = (Func<DataSet>)context.UserState;
DataSet dataSet = action.EndInvoke(result);
// dispose the database connection
dbHelper.Dispose();
Result.Set(context, dataSet);
// return the state
return dataSet;
}
}
Then created a workflow sample and dropped this activity on workflow and set the required properties. But when I am trying to access this activity to get dataset as a result, it is returning nothing. If I debug out the code, then it goes in the EndExecute method and fills the dataset properly. but nothing is returned to the workflow from where we are calling it, below is code used in program.cs of workflow application sample:
Activity oActivity = new Workflow1();
Dictionary<string, object> result = WorkflowInvoker.Invoke(oActivity);
Here it returns 0 keys in dictionary object result. Can anyone help on how can I get Dataset back here?
I am using .Net 4.0