in
Forums
Blogs
Files
Devexpress.Com
ClientCenter
DevExpress Channel

The ASPx Blog

ASPxGridView Screencast: Massive Dataset + XPO = Fast Grid

In the DotNetRocks show #246 on ASP.NET scalability, Stephen Forte mentions one of the biggest problems with scalability is loading large datasets in a paged grid.

What typically happens when displaying large datasets in a grid is that all the data is fetched instead of just the data needed for the current grid size and settings. This can be a performance problem with any dataset and it's a major problem with large datasets.

The Developer Express Data Controller (XPODataSource) solves this problem by automatically creating smart queries to fetch just the right amount of data.  Whether sorting, grouping or filtering, it will optimize queries to quickly pull only the necessary data. It also does intelligent caching so it doesn't have to run the same query if it was recently run. The XPODataSource and everything needed to run it comes with the ASPxGridView & Editors Library, so if you have the ASPxGridView component, then you have eXpressPersistent Objects (XPO) and the XPODataSource.

You can use the Devexpress Data Controller to make the ASPxGridView extremely fast and responsive with massive datasets. Everything you need is packaged with the ASPxGridView to work with large datasets. The steps aren't complicated, basically all you have to do is initialize XPO, create an XPODataSource and then hook it up to the ASPxGridView.

I've prepared a screencast and a set of written steps to show you how to hook it up. They both present the same information so you can use either or both to learn how to achieve grid speed nirvana.

Here's the screencast - I move pretty quick so it's only about 5 minutes long:

image

The written steps and the sample files are below.

Let me know which tutorial style works best, or if you found both useful. Also, please try this out with your own database and tell me how it feels to quickly navigate a huge dataset with a web grid. Nice, isn't it? ;)


How to use the XPODataSource with the ASPxGridView:

Use the steps below to enable the XPODataSource to work with an ASPxGridView:

Use Wizard for Class Generation

This is a one time step and doesn't need to be maintained. Add a new item to your project (App_Code directory). Select Persistent Classes v7.3 and give it a name. After pressing enter, the wizard appears letting you define your database connection to generate the classes from:

image

You can select the tables or just keep the default for all tables and the wizard will generate a file containing the classes.

image

The wizard generated file contains object representations of the database tables for use by the XPODataSource as you'll soon see. This file doesn't require any modification and can be closed:

image

Add Init Code

There are only two places that will require initialization code. The first is in the Global Application Class and the second is in the Page containing the XPODataSource. Start by adding a new item to your project (Global Application Class). In the Application_Start event, add the following code:

   void Application_Start(object sender, EventArgs e)
   {
        string conn = DevExpress.Xpo.DB.MSSqlConnectionProvider.GetConnectionString("servername", "username", "password", "databasename");
        DevExpress.Xpo.Metadata.XPDictionary dict = new DevExpress.Xpo.Metadata.ReflectionDictionary();
 
        dict.GetDataStoreSchema(typeof(Northwind.ServerSideGridTest).Assembly);
        DevExpress.Xpo.DB.IDataStore store = DevExpress.Xpo.XpoDefault.GetConnectionProvider(conn, DevExpress.Xpo.DB.AutoCreateOption.SchemaAlreadyExists);
        object layer = new DevExpress.Xpo.ThreadSafeDataLayer(dict, store);
        Application.Add("XpoLayer", layer);
   }

Oliver has a deeper explanation of this code here but in general there are two helper methods to note. The first is the GetConnectionString helper method in which you define your connection string. If you're using a trusted connection, remove the username and password parameters. The second method is the GetDataStoreSchema where you define the large table that will be referenced/loaded.

The other place that requires the initialization code is in the Page_Init event of the Page you have the ASPxGridView and XPODataSource. This is explained in the next section.

Create your web page

The final step is very simple since you've done the 2 steps which are probably the hardest. Create a new web page and add an ASPxGridView and XPODataSource control (DX: Web v7.3 tab). For the XPODataSource, set the ServerMode to true and TypeName to the large table that will be displayed by the ASPxGridView:

image

Set the ASPxGridView's DataSource property to the XPODataSource:

image

Add the following Page_Init method to your page:

   using DevExpress.XPO; 
 
   UnitOfWork unitOfWork;
   private void Page_Init(object sender, EventArgs e)
   {
        unitOfWork = new UnitOfWork(Application["XpoLayer"] as IDataLayer);
        XpoDataSource1.Session = unitOfWork;
   }

 

That's it, you're done! You can now run the project and experience the fast and amazing performance of using the Developer Express Data Controller.

I've created a sample for download. The sample uses the Adventure Works LT database. If you don't have this database then you can download it from CodePlex. I recommend creating a project that uses your own database and large tables. You need to experience this change with data that makes you want to tear your hair out. Hook it up to the XPODataSource, view it with the ASPxGridView and then tell me how much better life is in the fast lane.

Published Nov 20 2007, 02:14 AM by Mehul Harry (Developer Express)

Comments

 

Linton said:

Nice article, thanks. I'm wondering if you plan to extend this sample to demonstrate the code needed to implement CRUD with XPODataSource

November 20, 2007 11:02 AM
 

Michael Chean said:

How about extending it for business rules?  Where do they go?

November 20, 2007 1:28 PM
 

John Jackovin said:

Any further thought on doing some screencasts specifically designed for smart clients?  We have a smart client that uses your grid and retrieves a massive amount of data.  I would love to see some casts that show the unique situations encountered using web services between the client app and the data store.

November 20, 2007 2:21 PM
 

EP said:

What if you want to add records or edit records? How would that work with XPO? I noticed that there are no select querys, so I'm wondering what would be the equivilant of update/delete queries. What if I want to pass certain variables to the select strings.. Or is XPO used for strictly represntation purposes.

November 20, 2007 4:56 PM
 

Matthew MacSuga said:

Awesome screencast !!  I think it would be fantastic if you showed an additional one, based on the same premis but with WinForms, instead of ASP.NET.

November 20, 2007 7:00 PM
 

Mehul Harry (Developer Express) said:

Hi Robert,

Thanks, Insert/Update/Delete is easyily done on the grid events. Using XPODataSource, get the XPO object and then change the properties (Insert/Update/Delete) or create a new object. I'll see if we can get a sample but I recommend taking a look at the following articles:

www.devexpress.com/Help

November 21, 2007 1:18 AM
 

Mehul Harry (Developer Express) said:

Hi Michael,

You'd have to choose. If you have an XPO object that has a property which is calculated based on other properties/method/classes, then it's not possible to sort/group/filter by it (using the server mode).

For further information look in the XPO help, XPO forums and XPO blog.

XPO is a pretty mature product that has been released for many years and used a lot.

Thanks.

November 21, 2007 1:40 AM
 

Mehul Harry (Developer Express) said:

Hi Matthew,

Thanks. There is a screencast for the XtraGrid you can watch here: www.devexpress.com/.../dataManagementTest.html

November 21, 2007 1:43 AM
 

Mehul Harry (Developer Express) said:

Hello EP,

Please see my response to Robert as it contains a link to helpful articles on XPO.

Thanks.

November 21, 2007 2:19 AM
 

Developer Express - Ray said:

Hi John

If you have specific suggestions for screencasts, please send me or Julian an Email and we'll do our best to organize things.

November 21, 2007 2:26 AM
 

  ASPxGridView Screencast: Massive Dataset + XPO = Fast Grid by rssdreams said:

Pingback from    ASPxGridView Screencast: Massive Dataset + XPO = Fast Grid by rssdreams

November 21, 2007 4:22 AM
 

Shankar said:

Hi Mehul/Robert

Nice demo.

The CRUD needs to obey laws of security at a site and be offered as part of a grid and detail with row/column access rights

Can it be specified to grid as an XML and executed at run time

November 24, 2007 7:37 AM
 

Richard Hill said:

I am following this in my own project, and when I get to the database connection, if I try and access one database it only lists 4 tables ( out of around 100).   If I link to another on the same server, it shows them all.  

Coincidently (possibly) the 4 tables it shows are aspnet_paths,

aspnet_applications,aspnet_users,aspnet_roles

Any ideas how to see the rest of the tables ?

December 5, 2007 7:23 AM
 

RAUL TORTIMA said:

I currently have EntitySpaces as my main datalayer, and I like it a lot.

XPO came for free when I bought AspxGridView, so I wonder what would be faster, using ES or XPO...

December 17, 2007 6:34 AM
 

Mehul Harry (Developer Express) said:

Richard,

Sounds like your querying your local SqlExpress tables. Double check the sql server name. Also check your rights. If your still able to figure it out then please contact our support team.

Thanks.

December 19, 2007 2:38 AM
 

Mehul Harry (Developer Express) said:

Hello Raul,

XPO would be faster because of the interface the ASPxGridView supports to use the XPODataSource. No other datasources currently support this technology yet.

Thanks.

December 19, 2007 2:40 AM
 

anant tiwari said:

Hi,

i have the problem in using xpodatasource as its not giving me the wizard for setting the datasource ,userid,password, etc

i do have the component installed on my machine can you plz suggest any idea.....

Thankx for the same

February 19, 2008 8:06 AM
 

Anant said:

Hi

I m unable to get the wizard when i added the xpodatasource as displayed in the clip

Thankx in advance

February 19, 2008 8:08 AM
 

.Net World said:

In a previous post , I showed you how to use the powerful Server mode feature in ASPxGridView and XtraGrid

March 29, 2008 2:13 AM
 

The ASPx Blog said:

Check out this 4 minute video on a very useful feature in the 2008 vol 2 release. The video/screencast

July 10, 2008 7:01 PM

Leave a Comment

(required)  
(optional)
(required)  
Verification code: Required
   
Add
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED