20-08-21 07:10 PM
Hello everyone,
I am trying to develop an code for BluePrism using C#. For this code, I am trying to use LINQ to create a Query.
However, the code stage does not understand the command lines of the Query.
var results = FROM e in dt1
right join c in dt2
on e.ColumnNameDT1 equals c.ColumnNameDT2 into joined
from j in joined.DefaultIfEmpty());
The System.Linq is already imported (I am using for other codes).
How can I edit this code for BluePrism undestand the commands for SQL?
Thanks and Regards,
23-08-21 05:52 PM
1 // create input DataTables
2 DataTable dt1 = new DataTable();
3 DataTable dt2 = new DataTable();
4 DataTable dtResult = new DataTable();
5
6 dt1.Columns.Add("ColumnNameDt1", typeof(string));
7 dt1.Columns.Add("Dt1Value", typeof(string));
8
9 dt2.Columns.Add("ColumnNameDt2", typeof(string));
10
11 dt1.Rows.Add("hello", "world");
12 dt2.Rows.Add("hello");
13
14 // create temporary output DataTable
15 dtResult.Columns.Add("ColumnNameDt1", typeof(string));
16 dtResult.Columns.Add("ColumnNameDt2", typeof(string));
17 dtResult.Columns.Add("Dt1Value", typeof(string));
18
19 // LINQ Query
20 var results =
21 from c in dt2.AsEnumerable()
22 join e in dt1.AsEnumerable()
23 on c.Field<string>("ColumnNameDt2") equals e.Field<string>("ColumnNameDt1") into joined
24 from j in joined.DefaultIfEmpty()
25 select dtResult.LoadDataRow(
26 new object[]
27 {
28 c.Field<string>("ColumnNameDt2"),
29 j.Field<string>("ColumnNameDt1"),
30 j == null ? String.Empty : j.Field<string>("Dt1Value")
31 },
32 false);
33
34 // Send LINQ query result to a new DataTable
35 DataTable newTable = results.CopyToDataTable<DataRow>();
23-08-21 06:09 PM
23-08-21 06:33 PM
Hi @ewilson,
The only errors I get are compilation: missing ; or ")". The code works fine in Visual Studio.
Thanks and Regards,
Rafael
23-08-21 07:04 PM