Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes, you can use Linq queries with Workflow. In WF what you are referring to as a rule is an expression that is evaluated at runtime. Your query is selecting a subset of the orderliness based on a criteria. </p> <p>For example, if I have a collection of names and I want to see only names that begin with 'R'. I could write the following code.</p> <pre><code>private static void ShowQueryWithCode(IEnumerable&lt;string&gt; names) { Console.WriteLine("LINQ Query in Code - show names that start with 'R'"); // Assuming there are no null entries in the names collection var query = from name in names where name.StartsWith("R") select name; // This is the same thing as // var query = names.Where(name =&gt; name.StartsWith("R")); foreach (var name in query) { Console.WriteLine(name); } Console.WriteLine(); } </code></pre> <p>To do the same with Workflow</p> <p><strong>Step 1: Create a Workflow with an In Argument of type IEnumerable</strong></p> <p>Here you can see that I've added the in argument <img src="https://i.stack.imgur.com/K9RNy.png" alt="in argument"></p> <p><strong>Step 2: Add a Variable for the query of type IEnumerable</strong></p> <p>Before you can add a variable you need to include an activity which has variables. In this workflow I've added a sequence.</p> <p><img src="https://i.stack.imgur.com/xTpKD.png" alt="variable"></p> <p><strong>Step 3: Assign the query the LINQ expression you want to use</strong> You can use a method chain or query syntax.</p> <p><img src="https://i.stack.imgur.com/GIn9c.png" alt="expression"></p> <p><strong>Step 4: Iterate over the collection</strong></p> <p>In the completed workflow I used a ForEach activity to iterate the list of names and write them to the console.</p> <p><img src="https://i.stack.imgur.com/UlGAw.jpg" alt="Workflow1"></p> <p>This example uses C# in .NET 4.5 but the same technique can be used with Visual Basic.</p> <p>You can download the sample code <a href="http://code.msdn.microsoft.com/Using-Linq-Queries-in-5b17f6be" rel="nofollow noreferrer">here</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload