LINQPad is XPO’s new best friend!

XPO Team Blog
27 December 2011

LINQ is .NET Language-Integrated Query. It's included in .NET Framework 3.5 and you can use it in Visual Studio 2008 projects. XPO has officially supported LINQ since v7.3 and since then we have continued to improve and support it. Nowadays LINQ to XPO is very mature, extendable (How to: Implement Custom Functions and Criteria in LINQ to XPO) and powerful (Free Joins). In the latest version we make it even easier to use LINQ to XPO since we only distribute one assembly, DevExpress.XPO.dll, which includes everything! (custom providers as well).

XPO can talk transparently to a large list of database systems. It was already possible to make complex queries using our standard criteria syntax, however using LINQ offers some great advantages.

  1. No magic strings, like you have in standard criteria syntax,
  2. Intellisense support making it easier and faster to construct your queries,
  3. Compile time checking,
  4. Learning to write LINQ queries/lambdas is a must learn for .NET developers,

The benefits are clear, however there is a caveat when using LINQ. It is not possible to use Edit and Continue and with even the smallest change you need to restart your debugging session. As a result your development speed is decreased dramatically.

The solution as always is to use the right tool and in this case the right tool is LINQPad. It provides a flexible UI allowing you to use LINQ in various ways.

In our latest version our team released an XPO context driver for LINQPad. Let’s see how to configure it.

Firstly we need to install the driver found at C:\DevExpress 2011.2\Components\Tools\DXperience\XPOContextDriver.lpx.

image

Secondly we need to setup a new connection.

image

In this example we are going to use the MainDemo assembly containing the business objects.

image

LINQPad populated the domain in a hierarchical treelist. This allows us to enjoy using drag & drop plus intellisence in its expression editor to form the LINQ queries. Furthermore it is possible to use your style of language as demonstrated below.

image

The cool part is that LINQPad, written by the great Joe Albahari, is available for free. It is strongly recommended as a great way to learn LINQ.

Now for the fun part, let’s see it in action. Imagine we have the following code in our VS.

var queryable = from c in contacts

                let tasks = c.Tasks.Where(t => t.ActualWork < 0)

                where tasks.Any()

                orderby c.LastName

                select new {

                               c.LastName,

                               Orders = tasks.Count(),

                           };

 

We wish to see the results of queryable variable ,the best way to achieve this is to set a breakpoint then hit F5. Next we wait for our app to load and navigate to the action that will hit the breakpoint. Finally we must select the queryable variable and hit Shift+F9 to invoke the debugger window and examine the result set. Now we can try to make our requirements more complex. Lets say we also want to examine the result set when ActualWork>10. The solution is really easy when using LINQPad, we simply need to copy paste the code from VS to LINQPad the expression editor like this,

image

After this we can quickly and easily form queries as we wish and examine their result sets instantly. Using the excellent and cheap LINQPad Autocompletion it is possible to use VS like intelligence to further speed up your development.

image

PS: eXpandFrameWork contributors are already using the Autocompletion feature since LINQPad offered a license for its contributors.

We would appreciate your feedback on this post. Has it been useful to you? Feel free to contact us with any further questions

Free DevExpress Products – Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We’ll be happy to follow-up.
Sascha
Sascha

Tested & Love it ;)

27 December 2011
Nguyen Van
Nguyen Van

DevExpress.Xpo.XPCollection' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument of type 'DevExpress.Xpo.XPCollection' could be found (press F4 to add a using directive or assembly reference)

Did you modify the business objects of MainDemo assembly?

28 December 2011
Marc Greiner (DevExpress MVP)
Marc Greiner (DevExpress MVP)

Hello Tolis! And thanks a lot for this great blog post!

28 December 2011
Yaron Librach
Yaron Librach

The driver is not working with LINQPad 4.31 (latest version). LINQPad says it loads it successfully, but it is nowhere to be found in the list of available drivers. After poking around the LINQPad forums, it seems that this is a problem with the DevExpress assembly, and it needs to be updated.

28 December 2011
Alex Sav (DevExpress)
Alex Sav (DevExpress)

Hello Yaron,

We developed and tested XPOContextDriver with both v4.31.0 and v2.31.0 versions of LINQPad, and it worked fine. If you have any difficulties using our XPOContextDriver, please contact our support team at devexpress.com/.../Center. We will do our best to help you.

29 December 2011
Robert Flippo
Robert Flippo

Any change that DC will be supported?

30 December 2011
Thomas Wieser
Thomas Wieser

Is there a way to connect to Sybase ASA11? Or any way to get my own ConnectionProvider into the XPOContextDriver?

3 January 2012
Tim Shnaider
Tim Shnaider

Awesome, great work.  Now all you have to do is get XPO Linq to support subqueries and I and a lot of people will be very happy!

17 January 2012
Aleksandr Makarov_1
Aleksandr Makarov_1

Error with Firebird

2 March 2012
asava samuel
asava samuel

Apostolis Bekiaris

I haven't used it, but Kellerman Software has a LINQ provider for Firebird

www.kellermansoftware.com/p-47-net-data-access-layer.aspx

4 March 2013
Michiel Blotwijk
Michiel Blotwijk

Thanks for your blog entry, Tolis. Screenshots and pathes look a bit different with the current releases of LinqPad and Devexpress, but nothing too complicated.

31 May 2014

Please login or register to post comments.