Skip to main content

LINQ to SQL

  • 2 minutes to read

The Data Source Configuration Wizard allows you to bind the PivotGridControl to an SQL database using LINQ to SQL at design time. This topic shows how to do this.

  1. Click the Data Source Wizard button placed on the PivotGridControl or use the corresponding command in the control’s smart tag.

    WinPivot_DataSourceButton

  2. In the invoked Data Source Configuration Wizard, select LINQ to SQL

    DataSourceConfigurationWizard_SelectLinq

    … and click the New Data Source button placed within the Data Sources area.

    DataSourceConfigurationWizard_SelectAdoNet_NewDataSource

  3. The following message will appear.

    DataSourceConfigurationWizard_RebuildWarning

    Click OK.

  4. Make sure that the LINQ to SQL Classes item is selected in the invoked dialog. Then, specify the required name and click Add.

    Pivot_AddLinqClassesDialog

    To learn how to create LINQ to SQL classes that are based on objects in a database, see the following topic: Creating LINQ to SQL Classes.

    Important

    After you creat a data model, rebuild the solution.

  5. After creating LINQ to SQL classes, click the Data Source Wizard button again.

    WinPivot_DataSourceButton

  6. In the invoked Data Source Configuration Wizard, select the created data model.

    DataSourceConfigurationWizard_Linq_SelectContextl

    Click Next.

  7. On the next page, select the required binding method.

    DataSourceConfigurationWizard_EF_SelectBindingMethod

    Select Direct Binding to Data Source and click Next.

  8. On the final page, you can specify the table.

    DataSourceConfigurationWizard_AdoNet_SelectTable

    Select the required table and click Finish.

  9. The following code will be generated by the Data Source Configuration Wizard.

    public Form1()
            {
                // This line of code is generated by Data Source Configuration Wizard
                pivotGridControl1.DataSource = new WinFormsPivot.NorthwindDataContext().SalesPersons;
            }
    

    You can work now with the created data source at runtime. For instance, to retrieve fields from the connected data source, call the PivotGridControl.RetrieveFields method.

See Also