Skip to main content

Bind Grid View to Large Data (LINQ)

  • 3 minutes to read

You can enable server mode for any Language-Integrated Query (LINQ) provider. The LinqServerModeDataSource component is designed for ASP.NET applications, and serves as a data source for the ASPxGridView control.

When a user performs data operations (for example, sort and group actions) the LinqServerModeDataSource component analyzes the grid’s current state and generates smart queries to receive only those records that must be displayed on-screen. These requests are passed to the associated LINQ provider. The LINQ provider translates these requests into the required queries and executes them.

Example

The LinqServerModeDataSource component allows you to bind ASPxGridView to the LINQ to SQL Classes and enable server mode.

Create Data Classes

  1. Add the LINQ to SQL Classes. cdLINQ_addClasses

  2. Data classes can then be created and edited in the Object Relational Designer (O/R Designer). The O/R Designer has a visual design surface to create LINQ to SQL entity classes and relationships based on database objects. The O/R Designer currently supports only SQL Server 2000, SQL Server 2005, SQL Server 2008, and SQL Server Express.
    You can create and map entity classes to tables and views. To do this, drag database tables and views from Server Explorer or Database Explorer onto the O/R Designer.

  3. Save your changes, close the O/R Designer, and rebuild the solution.

LinqServerModeDataSource

  1. Drag the LinqServerModeDataSource component from the Visual Studio toolbox and drop it onto the ASPX Page. Note that the LinqServerModeDataSource component requires the DevExpress.Data.Linq namespace.

  2. Use the LinqServerModeDataSource.ContextTypeName property to specify the type of objects retrieved from the data source.

  3. Use the LinqServerModeDataSource.TableName property to specify the data table name.

  4. Bind the ASPxGridView control to the LinqServerModeDataSource component, and specify the grid’s ASPxGridBase.KeyFieldName property.

  5. You can use the Selecting event to dynamically assign data to the grid.

<%@ Register Assembly="DevExpress.Web.vXX.Y, Version=XX.Y.ZZ.0, Culture=neutral,
    PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Data.Linq" TagPrefix="dx" %>

<dx:ASPxGridView ID="ASPxGridView1" DataSourceID="LinqServerModeDataSource1" AutoGenerateColumns="true" runat="server">
</dx:ASPxGridView>

<dx:LinqServerModeDataSource ID="LinqServerModeDataSource1" OnSelecting="LinqServerModeDataSource1_Selecting" runat="server" />
protected void LinqServerModeDataSource1_Selecting(object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e) {
    DataClassesDataContext db = new DataClassesDataContext();
    e.KeyExpression = "EmployeeID";
    e.QueryableSource = from employee in db.Employees
        join order in db.Orders on employee.EmployeeID equals order.EmployeeID
            select new {
                employee.EmployeeID, employee.FirstName, employee.LastName, order.OrderID, order.OrderDate
            };
}

Database Server Mode Limitations

In database server mode, ASPxGridView does not have simultaneous access to bound data in its entirety. This imposes some limitations on the grid’s features, which are still available in regular binding mode. See the following topic for information on features that are not supported in server mode: Database Server Mode Limitations.

See Also