Can I use a LINQ Query such as the following in a Workflow?
private static void ShowQueryWithCode(IEnumerable<string> 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 => name.StartsWith("R")); foreach (var name in query) { Console.WriteLine(name); } Console.WriteLine();}
private static void ShowQueryWithCode(IEnumerable<string> 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 => name.StartsWith("R"));
foreach (var name in query) { Console.WriteLine(name); } Console.WriteLine();}
Yes, you can use LINQ with a Workflow in exactly the same way.
Here you can see that I've added the in argument
Before you can add a variable you need to include an activity which has variables. In this workflow I've added a sequence.
You can use a method chain or query syntax.
In the completed workflow I used a ForEach<string> activity to iterate the list of names and write them to the console.
This example uses C# in .NET 4.5 but the same technique can be used with Visual Basic.
When you run it you can see that both methods work the same.
Happy Coding!
Ron Jacobs http://blogs.msdn.com/rjacobs Twitter: @ronljacobs