workflow doesn't refer to System.Data.DataSetExtensions
Greetings,
In my workflow we got a datatable as result of a SQL query. I'm trying to get the rows (of DataRow type) in the datatable by using DataTabel.AsEnumerable(). But workflow couldn't recognize AsEnumerable function for DataTable as the function belongs to System.Data.DataSetExtension which Workflow doesn’t refer to. Is there a way to fix or alternative way to read all columns of a row in the table? (p.s. thought about convert DataTable to DataItemList but this way is too inefficient). Thanks.
-
Hi Jack,
Instead of using the AsEnumerable method you can use the Cast() method. Using an example DataTable named "dataTable1" you can use the ForEach<> activity with a TypeArgument of DataRow; for the values use dataTable1.Rows.Cast(Of DataRow). In the body of the ForEach<> activity you can access the individual columns as item(<column name>), or item.ItemArray(<column index>).
Nicholas
0 -
Thanks Nicholas it works!
However, when I try to get the value of a column in a row using item("columnA").ToString() it gives me the following error..
Error: Aborted exception: 'Type 'System.Collections.Generic.IEnumerable`1[System.Data.DataRow]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.'.
Any suggestions?
0 -
Hi Jack
try capturing the value that you want into a string variable first and then show that in your Alert activity.
I assume that is what you are doing with item("columnA").ToString()
Ralph
0 -
Hi Ralph,
Just tried as you suggested still have the same issue. I attached the workflow code below.
<Activity mc:Ignorable="sads sap" x:Class="{x:Null}"
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:eac="clr-namespace:ESRI.ArcGIS.Client;assembly=ESRI.ArcGIS.Client"
xmlns:eacg="clr-namespace:ESRI.ArcGIS.Client.Geometry;assembly=ESRI.ArcGIS.Client"
xmlns:eact="clr-namespace:ESRI.ArcGIS.Client.Tasks;assembly=ESRI.ArcGIS.Client"
xmlns:gce="clr-namespace:Geocortex.Core.Extensions;assembly=Geocortex.Core"
xmlns:gcx="http://apis.geocortex.com/2009"
xmlns:gfc="clr-namespace:Geocortex.Forms.Client;assembly=Geocortex.EssentialsWpfApi"
xmlns:gfci="clr-namespace:Geocortex.Forms.Client.Items;assembly=Geocortex.EssentialsWpfApi"
xmlns:gr="clr-namespace:Geocortex.Reporting;assembly=Geocortex.Reporting"
xmlns:gwa="clr-namespace:Geocortex.Workflow.Activities;assembly=Geocortex.Workflow"
xmlns:gwa1="clr-namespace:Geocortex.Workflow.Activities;assembly=Geocortex.Workflow.Activities"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities"
xmlns:s="clr-namespace:System;assembly=System.Core"
xmlns:s1="clr-namespace:System;assembly=System"
xmlns:s2="clr-namespace:System;assembly=mscorlib"
xmlns:s3="clr-namespace:System;assembly=System.ComponentModel.Composition"
xmlns:s4="clr-namespace:System;assembly=System.ServiceModel"
xmlns:sa="clr-namespace:System.Activities;assembly=System.Activities"
xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
xmlns:sc="clr-namespace:System.Collections;assembly=mscorlib"
xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"
xmlns:sd="clr-namespace:System.Data;assembly=System.Data"
xmlns:sl="clr-namespace:System.Linq;assembly=System.Core"
xmlns:sxs="clr-namespace:System.Xml.Serialization;assembly=System.Xml"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<x:Members>
<x:Property Name="argument1" Type="InArgument(x:String)" />
</x:Members>
<sap:VirtualizedContainerService.HintSize>728,1488</sap:VirtualizedContainerService.HintSize>
<mva:VisualBasic.Settings>Assembly references and imported namespaces serialized as XML namespaces</mva:VisualBasic.Settings>
<Sequence sap:VirtualizedContainerService.HintSize="316,858" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces">
<Sequence.Variables>
<Variable x:TypeArguments="x:String" Name="string1" />
<Variable x:TypeArguments="sd:DataTable" Name="dataTable1" />
<Variable x:TypeArguments="scg:IList(gcx:DataItem)" Name="iList1" />
<Variable x:TypeArguments="x:String" Name="string2" />
<Variable x:TypeArguments="sd:DataTable" Name="dataTable2" />
<Variable x:TypeArguments="x:Int32" Name="rowsAffected" />
</Sequence.Variables>
<sap:WorkflowViewStateService.ViewState>
<scg:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<gwa1:SqlQuery CommandText="Select * From test.dbo.PAR_RESPONSE" ConnectionString="Server=localhost\sqlexpress;Database=Test;Trusted_Connection=True;" sap:VirtualizedContainerService.HintSize="294,136" ProviderName="System.Data.SqlClient" Results="[dataTable1]">
<sap:WorkflowViewStateService.ViewState>
<scg:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg:Dictionary>
</sap:WorkflowViewStateService.ViewState>
</gwa1:SqlQuery>
<Assign sap:VirtualizedContainerService.HintSize="294,60">
<Assign.To>
<OutArgument x:TypeArguments="x:String">[dataTable1.TableName]</OutArgument>
</Assign.To>
<Assign.Value>
<InArgument x:TypeArguments="x:String">Result Table</InArgument>
</Assign.Value>
<sap:WorkflowViewStateService.ViewState>
<scg:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg:Dictionary>
</sap:WorkflowViewStateService.ViewState>
</Assign>
<ForEach x:TypeArguments="sd:DataRow" DisplayName="ForEach<DataRow>" sap:VirtualizedContainerService.HintSize="294,458" Values="[dataTable1.Rows.Cast(Of DataRow)]">
<sap:WorkflowViewStateService.ViewState>
<scg:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<ActivityAction x:TypeArguments="sd:DataRow">
<ActivityAction.Argument>
<DelegateInArgument x:TypeArguments="sd:DataRow" Name="item" />
</ActivityAction.Argument>
<Sequence sap:VirtualizedContainerService.HintSize="264,310">
<Sequence.Variables>
<Variable x:TypeArguments="x:String" Name="strSchemaName" />
</Sequence.Variables>
<sap:WorkflowViewStateService.ViewState>
<scg:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<Assign sap:VirtualizedContainerService.HintSize="242,60">
<Assign.To>
<OutArgument x:TypeArguments="x:String">[strSchemaName]</OutArgument>
</Assign.To>
<Assign.Value>
<InArgument x:TypeArguments="x:String">[item("schemaID").ToString]</InArgument>
</Assign.Value>
</Assign>
<gwa1:Alert sap:VirtualizedContainerService.HintSize="242,86" Text="[strSchemaName]" />
</Sequence>
</ActivityAction>
</ForEach>
</Sequence>
</Activity>0 -
Hi Jack,
You can't use a client-side activity, like an Alert activity, inside the ForEach<> activity when enumerating the rows. Workflow will try and serialize the state of your workflow to send to the client to do the alert and as the DataRow is still in scope and can't be serialized the error you see is thrown.
Try replacing the Alert activity with a Log activity if you are just interested in seeing the value for testing. If you wish to use the value for further processing you could add it to a collection and then process the collection when the DataRow is out of scope.
Nicholas
0 -
Thanks Nicholas, that answered my question.
regards,
Jack
0
Please sign in to leave a comment.
Comments
6 comments