XPO

LINQPad is XPO’s new best friend!

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

Published Dec 27 2011, 10:23 AM by
Bookmark and Share

Comments

Sascha

Tested & Love it ;)

December 27, 2011 2:06 PM

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?

December 28, 2011 5:50 AM

Marc Greiner (DevExpress MVP)

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

December 28, 2011 10:40 AM

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.

December 28, 2011 10:16 PM

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.

December 29, 2011 7:54 AM

Robert Flippo

Any change that DC will be supported?

December 30, 2011 3:54 AM

Thomas Wieser

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

January 3, 2012 10:29 AM

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!

January 17, 2012 9:02 PM

Aleksandr Makarov_1

Error with Firebird

March 2, 2012 10:07 AM

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

March 4, 2013 2:51 AM

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.

May 31, 2014 11:09 AM
LIVE CHAT

Chat is one of the many ways you can contact members of the DevExpress Team.
We are available Monday-Friday between 7:30am and 4:30pm Pacific Time.

If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

FOLLOW US

DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible.

Copyright © 1998-2017 Developer Express Inc.
All trademarks or registered trademarks are property of their respective owners