<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Code Stage - C# Linq SQL in Digital Exchange</title>
    <link>https://community.blueprism.com/t5/Digital-Exchange/Code-Stage-C-Linq-SQL/m-p/96571#M2953</link>
    <description>Hi Rafael,&lt;BR /&gt;&lt;BR /&gt;Is there a specific error message you receive from Blue Prism? Have you tried running this code in Visual Studio or VS Code to validate it?&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Eric​</description>
    <pubDate>Mon, 23 Aug 2021 17:09:15 GMT</pubDate>
    <dc:creator>ewilson</dc:creator>
    <dc:date>2021-08-23T17:09:15Z</dc:date>
    <item>
      <title>Code Stage - C# Linq SQL</title>
      <link>https://community.blueprism.com/t5/Digital-Exchange/Code-Stage-C-Linq-SQL/m-p/96569#M2951</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;I am trying to develop an code for BluePrism using C#. For this code, I am trying to use LINQ to create a Query.&lt;/P&gt;
&lt;P&gt;However, the code stage does not understand the command lines of the Query.&lt;/P&gt;
&lt;PRE class="language-csharp"&gt;&lt;CODE&gt;var results = FROM e in dt1
right join c in dt2 
on e.ColumnNameDT1 equals c.ColumnNameDT2 into joined 
from j in joined.DefaultIfEmpty());&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;
&lt;/P&gt;&lt;P&gt;The System.Linq is already imported (I am using for other codes).&lt;/P&gt;
&lt;P&gt;
&lt;/P&gt;&lt;P&gt;How can I edit this code for BluePrism undestand the commands for SQL?&lt;/P&gt;
&lt;P&gt;
&lt;/P&gt;&lt;P&gt;Thanks and Regards,&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 18:10:50 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Digital-Exchange/Code-Stage-C-Linq-SQL/m-p/96569#M2951</guid>
      <dc:creator>RafaelFernandes</dc:creator>
      <dc:date>2021-08-20T18:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: Code Stage - C# Linq SQL</title>
      <link>https://community.blueprism.com/t5/Digital-Exchange/Code-Stage-C-Linq-SQL/m-p/96570#M2952</link>
      <description>Hi Rafael,&lt;BR /&gt;&lt;BR /&gt;I assume &lt;STRONG&gt;dt1&lt;/STRONG&gt; and &lt;STRONG&gt;dt2&lt;/STRONG&gt; are both DataTables and that your goal is to get a final DataTable that contains the content of the joined &lt;STRONG&gt;dt1&lt;/STRONG&gt; and &lt;STRONG&gt;dt2&lt;/STRONG&gt; tables. If so, the query will need some adjustments before it will compile properly. I've built up your original query into something that compiles in Visual Studio and Blue Prism. You will probably need to edit it a bit further to fit with the actual data in your DataTables.&lt;BR /&gt;&lt;BR /&gt;Here are the main ideas to consider in the below query:&lt;BR /&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;EM&gt;Lines 1-17&lt;/EM&gt;: I'm constructing DataTables so I have some data to experiment with. &lt;STRONG&gt;dtResult&lt;/STRONG&gt; is a temporary table to hold the joined DataTable result once we're in the query - the columns need to match exactly with what the joined output will be&amp;nbsp; (i.e. Lines 15-17 mirror Lines 29-30).&lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;Lines&amp;nbsp; 21-22&lt;/EM&gt;: I don't think LINQ can do a right join - everything is a left join. So flip the order of the tables (start with&amp;nbsp;&lt;STRONG&gt;dt2 &lt;/STRONG&gt;and left join &lt;STRONG&gt;dt1&lt;/STRONG&gt; into it to effectively make a right join).&lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;Lines 21-22&lt;/EM&gt;: Add the &lt;STRONG&gt;.AsEnumerable()&lt;/STRONG&gt; method on the DataTables - otherwise they don't play nicely with LINQ.&lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;Line 23&lt;/EM&gt;: Note how the column names are referenced (...&lt;STRONG&gt;Field&amp;lt;[datatype]&amp;gt;("ColumnName")&lt;/STRONG&gt;) -- this is because DataTables are being used. I use &lt;STRONG&gt;string&lt;/STRONG&gt; for all the field datatypes, but your columns may be composed of numbers, booleans, or other types, so you will have to match yours to your data appropriately.&lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;Lines 25-32&lt;/EM&gt;: The LINQ query needs to end with a &lt;STRONG&gt;se&lt;/STRONG&gt;&lt;STRONG&gt;lect&lt;/STRONG&gt; clause. In this case, I'm using the &lt;STRONG&gt;dtResult&lt;/STRONG&gt; DataTable to load a data row containing the joined data from the original &lt;STRONG&gt;dt1&lt;/STRONG&gt; and &lt;STRONG&gt;dt2 &lt;/STRONG&gt;DataTables.&lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;Line 30&lt;/EM&gt;: In case there is no match for one of the joined rows, avoid a null exception by writing an empty string instead.&lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;Line 35&lt;/EM&gt;: Finally, use the &lt;STRONG&gt;CopyToDataTable&amp;lt;DataRow&amp;gt;()&lt;/STRONG&gt; method to place your LINQ query result into a new DataTable. At this point, you can output the new DataTable into a Blue Prism Collection when you exit the code stage.&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE class="language-csharp"&gt;&lt;CODE&gt;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&amp;lt;string&amp;gt;("ColumnNameDt2") equals e.Field&amp;lt;string&amp;gt;("ColumnNameDt1") into joined
24       from j in joined.DefaultIfEmpty()
25       select dtResult.LoadDataRow(
26           new object[]
27               {
28                   c.Field&amp;lt;string&amp;gt;("ColumnNameDt2"),
29                   j.Field&amp;lt;string&amp;gt;("ColumnNameDt1"),
30                   j == null ? String.Empty : j.Field&amp;lt;string&amp;gt;("Dt1Value")
31               }, 
32           false);
33
34    // Send LINQ query result to a new DataTable
35    DataTable newTable = results.CopyToDataTable&amp;lt;DataRow&amp;gt;();​&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BR /&gt;Relevant links&lt;BR /&gt;&lt;A href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/join-clause#left-outer-join" target="_blank" rel="noopener"&gt;Microsoft - LINQ Left Outer Join&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://stackoverflow.com/questions/20760681/linq-join-two-datatables" target="_blank" rel="noopener"&gt;StackOverflow - Joining two datatables&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/creating-a-datatable-from-a-query-linq-to-dataset" target="_blank" rel="noopener"&gt;Microsoft - Create DataTable from LINQ Query&lt;/A&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 23 Aug 2021 16:52:57 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Digital-Exchange/Code-Stage-C-Linq-SQL/m-p/96570#M2952</guid>
      <dc:creator>charliekovacs</dc:creator>
      <dc:date>2021-08-23T16:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: Code Stage - C# Linq SQL</title>
      <link>https://community.blueprism.com/t5/Digital-Exchange/Code-Stage-C-Linq-SQL/m-p/96571#M2953</link>
      <description>Hi Rafael,&lt;BR /&gt;&lt;BR /&gt;Is there a specific error message you receive from Blue Prism? Have you tried running this code in Visual Studio or VS Code to validate it?&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Eric​</description>
      <pubDate>Mon, 23 Aug 2021 17:09:15 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Digital-Exchange/Code-Stage-C-Linq-SQL/m-p/96571#M2953</guid>
      <dc:creator>ewilson</dc:creator>
      <dc:date>2021-08-23T17:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: Code Stage - C# Linq SQL</title>
      <link>https://community.blueprism.com/t5/Digital-Exchange/Code-Stage-C-Linq-SQL/m-p/96572#M2954</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.blueprism.com/t5/user/viewprofilepage/user-id/833"&gt;@ewilson&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;​The only errors I get are compilation: missing ; or ")". The code works fine in Visual Studio.&lt;BR /&gt;&lt;BR /&gt;Thanks and Regards,&lt;/P&gt;
&lt;P&gt;Rafael&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 17:33:52 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Digital-Exchange/Code-Stage-C-Linq-SQL/m-p/96572#M2954</guid>
      <dc:creator>RafaelFernandes</dc:creator>
      <dc:date>2021-08-23T17:33:52Z</dc:date>
    </item>
    <item>
      <title>Re: Code Stage - C# Linq SQL</title>
      <link>https://community.blueprism.com/t5/Digital-Exchange/Code-Stage-C-Linq-SQL/m-p/96573#M2955</link>
      <description>In the code snippet that's shown there's an extra ")" at the end before the semicolon. There's no associated opening "(" for it.&lt;BR /&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="35095.png"&gt;&lt;img src="https://community.blueprism.com/t5/image/serverpage/image-id/35156iB1A0A80CDEB32760/image-size/large?v=v2&amp;amp;px=999" role="button" title="35095.png" alt="35095.png" /&gt;&lt;/span&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Eric</description>
      <pubDate>Mon, 23 Aug 2021 18:04:55 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Digital-Exchange/Code-Stage-C-Linq-SQL/m-p/96573#M2955</guid>
      <dc:creator>ewilson</dc:creator>
      <dc:date>2021-08-23T18:04:55Z</dc:date>
    </item>
  </channel>
</rss>

