本文介绍了创建活动如何调用数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我创建了编码活动返回数据集 公共类DbQueryDataSet:AsyncCodeActivity < ; DataSet > { //私有变量 IDictionary < string, 参数 > 参数; DbHelper dbHelper; //公共参数 [DefaultValue(null)] public InArgument < string > ProviderName {get;组; } [DefaultValue(null)] public InArgument < string > ConnectionString {get;组; } [DefaultValue(null)] public InArgument < string > ConfigName {get;组; } [DefaultValue(null)] public CommandType CommandType {get;组; } [RequiredArgument] public InArgument < string > Sql {get;组; } [DependsOn(Sql)] [DefaultValue(null)] public IDictionary < string, 参数 > 参数 { get { if(this.parameters == null) { this。 parameters = new Dictionary < string, 参数 > (); } 返回this.parameters; } } / * public DbQueryDataSet() { this.CommandType = CommandType.Text; } * / protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context,AsyncCallback callback,object state) { //配置帮助对象访问数据库 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); //创建执行实际工作的操作 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); //处理数据库连接 dbHelper.Dispose(); Result.Set(context,dataSet); //返回状态返回dataSet; } } 解决方案 他的问题是我们创建了这个返回数据集的活动。 /> 然后我们创建了一个工作流示例并将此活动放在工作流上并设置了所需的属性。 但是当我们正试图访问此活动以获取数据集,因此它什么也没有返回。 如果我们调试代码,那么它会进入EndExecute方法并且正确填充数据集。 但是没有任何内容返回到我们调用它的工作流程,下面是工作流应用程序示例的program.cs中使用的代码: /> 活动oActivity = new Workflow1(); Dictionary < string, object > result = WorkflowInvoker.Invoke(oActivity); I have created coded activity return datasetpublic 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; } } 解决方案 His question is that we have created this activity which returns a Dataset.Then we created a workflow sample and dropped this activity on workflow and set the required properties.But when we are trying to access this activity to get dataset as a result, it is returning nothing.If we 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); 这篇关于创建活动如何调用数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-02 17:54