Showing posts with label LINQPad. Show all posts
Showing posts with label LINQPad. Show all posts

Thursday, May 4, 2017

Use Visual Basic functions in a LINQPad query

Occasionally, you want to include a Visual Basic (or C#) function such as IIF or Chr() in a LINQ query using LINQPad.  There is two steps to this:


  1. In the Query menu, choose Query Properties.
  2. In the Additional References tab, choose Add, and type Microsoft.VisualBasic.
  3. Then in the Additional Namespace Imports tab, choose the Pick from assemblies link.  Choose the Microsoft.VisualBasic.dll assembly, select the Microsoft.VisualBasic namespace, and then click Add Selected Namespace.

Tuesday, July 21, 2015

Query XML files with LINQ

If you regularly work with XML, knowing a technique to directly query it can be a real asset.  I have found LINQ to XML together with LINQPad to be really helpful.  The best thing to do is to simply show an example.  Here we have a trivial XML file that we load in and display:


Then, let's say we want to list all plants from the file:


The tricky part is that if there are namespaces in your xml (and there usually is), then you need to include the namepace in braces.