Skip to main content
A newer version of this page is available. .

Binding to a Data Source Using 'LINQ to SQL Classes'

  • 2 minutes to read

The PivotGridControl automatically operates in server mode if it is bound to appropriate supported data source. You can use dedicated data sources tailored to work with ‘LINQ to SQL Classes’. This example shows how to use LINQ query providers.

Creating Data Classes

  1. Add LINQ to SQL Classes to the project.

    Server Mode LINQ  Add LINQ to SQL classes

  2. Data classes can then be created and edited in an Object Relational Designer (O/R Designer). An O/R Designer provides a visual design surface for creating LINQ to SQL entity classes and relationships based on objects in a database. To learn more, see the MSDN topic.

    You can create and map entity classes to tables and views by dragging database tables and views from Server Explorer onto the O/R Designer.

    Server Mode LINQ OR Designer

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

Binding a Pivot Grid Control to the LinqServerModeSource component

  1. Drag the LinqServerModeSource component and drop it onto the Form.

    Server Mode Add LINQ Component

  2. Specify the type of objects retrieved from a data source using the LinqServerModeSource.ElementType and LinqServerModeSource.KeyExpression properties.

    
    linqServerModeSource1.ElementType = typeof(LinqServerModeApp.SalesPerson);
    linqServerModeSource1.KeyExpression = "OrderID";
    
  3. Specify the queryable source using the LinqServerModeSource.QueryableSource property. This property must be set in code.

    
    public Form1() {
        InitializeComponent();
        linqServerModeSource1.QueryableSource = new LinqServerModeApp.DataClasses1DataContext().SalesPerson;
    }
    
  4. Bind the Pivot Grid control to the LinqServerModeSource component.

    
    pivotGridControl1.DataSource = linqServerModeSource1;
    

Note

To learn how to bind the PivotGridControl to data using the Data Source Configuration Wizard, see the LINQ to SQL tutorial.

See Also