XtraGrid - Server-side Data Manipulation using LINQ Providers

In this lesson, you’ll learn how to use the powerful Server Mode feature, without using an XPO Data Source.

The XtraGrid supports the use of a LINQ Provider as a data source. When the Grid Control operates in Server Mode, it delegates all data processing to the server and downloads only records that need to be displayed on-screen. This allows you to dramatically increase performance against large datasets.

Previously, this mode could only be enabled using an XPO Data Source. Now, any LINQ Query Provider is also supported.

Let’s see how to bind an XtraGrid to a LINQ Provider.

1. First, I’m going to add the LINQ to SQL Classes to the project.

2. Data Classes can then be created and edited in the Object Relation Designer.

3. The Object Relational Designer provides a visual design surface for creating LINQ to SQL Entity Classes and Relationships based on Database Objects.

4. Currently, the Object Relational Designer, only support SQL Server and SQL Server Express Edition Databases.

5. Entity Classes can be created and mapped to tables and views using the Server Explorer or Database Explorer.

6. Using the Explorer, you can drag database tables and views onto the Object Relational Designer.

7. For this demo, I’ll drag the “Customers” table to the design surface.

8. And that’s it!

9. I’ll save the changes, close the Object Relational Designer, and Rebuild the solution.

10. Now, I’ll drop a “LINQ Server Mode Source” Component onto the form.

11. This component can be associated with any queryable source.

12. The element’s type and a queryable source need to be specified.

13. I’ll select the Customer object for the “Element Type”.

14. The “Queryable Source” should be specified in code.

15. I’ll switch to the code view and specify the queryable source property.

16. In this case, I’ll set the queryable source property to a new instance of the “Customers” class.
CODE (C#):
linqServerModeSource1.QueryableSource = new DataClasses1DataContext().Customers;

17. Now, I’ll bind the XtraGrid Control to the “Linq Server Mode Source” component.

18. We’ll also set the “Server Mode” option to True, so we can get the performance benefits.

19. Now, I can run the application to see the result.

20. The grid now behaves as it does against other data sources, but we also have the added benefit of speed using the server mode.