Linq example in Uipath?


#1

Can someone please share an example (.xaml) of how to use Linq in uipath ?

Thanks


#2

Hi Gary,

The question is more “How to use Linq in VB.Net”, at least in my experience. UiPath works like normal code (at least the expressions do), but Linq in VB.Net has some gotcha’s :frowning:. At least I find it more convoluted than C# Linq (at least with method syntax, query syntax is almost the same).

Please see attached simple example - shows both method syntax and query syntax.
Notice how the last assign, in the Select clause, the “z.ToString” is in brackets. This is actually required by the compiler, because in VB you can’t use Select methods that exist in Object class (so either bracket them like in the example, or use overloads that Object does not have).

It might help if you could elaborate what type of Linq you want to use (Xml, SQL, collection filtering etc.).

SmallTests.xaml (6.0 KB)


3. RPA Challenge - LINQ to extract values from datatable
#3

Thank you @andrzej.kniola ! I appreciate your help. I want to use Linq to SQL. Could you show me an example ? Thank you.


#4

For usual Linq to SQL types you’d normally build at least entity classes, which is not possible in the UiStudio directly (they could be imported via packages though).

Here is a great article from the creators of Linq to SQL that should give you a strong starting point. The logic itself is pretty simple, most of the work is building entity representations and queries themselves.

As a sidenote - have you tried using existing DB activities? For simple cases they’re usually enough.


#5

Thank you @andrzej.kniola! . I use DB activities extensively, Linq looks interesting, however it looks like its a bit more complicated than using myqls queries, which I am comfortable with. I will have a look at the article you sent me. Thank you for your help.