Entity Framework Data

  • 3 minutes to read

The Data Source Configuration Wizard allows you to bind the PivotGridControl to a SQL database using Entity Framework at design time. Follow the steps below to accomplish this task.

  1. Open the form with the PivotGridControl in Visual Studio Designer. Click the Data Source Wizard button located on the PivotGridControl design surface or use the related command in the control's smart tag.

    WinPivot_DataSourceButton

  2. In the invoked Data Source Configuration Wizard, select Entity Framework...

    DataSourceConfigurationWizard_SelectEF

    ... and click the New Data Source button located in the Data Sources area.

  3. The following message appears:

    DataSourceConfigurationWizard_RebuildWarning

    Click OK.

  4. Make sure that the ADO.NET Entity Data Model item is selected in the invoked dialog. Then, specify the name (in this example, NorthWindModel) and click Add.

    Pivot_AddEFDataModelDialog

  5. The following image gallery shows the Entity Data Model Wizard in three steps required to create the Data Model.

    When you click Finish at the last Entity Data Model Wizard screen, the following warning appears:

    Click OK to run the Entity Framework template that creates a data model.

  6. The created model looks as follows:

    entity-data-model-browser

IMPORTANT

After you create a data model, rebuild the solution.

  1. After creating a data model, click the Data Source Wizard button again.

    WinPivot_DataSourceButton

  2. In the invoked Data Source Configuration Wizard, select the created data source.

    DataSourceConfigurationWizard_EF_SelectModel

    Click Next.

  3. On the next page, select the binding method.

    DataSourceConfigurationWizard_EF_SelectBindingMethod

    Select Direct Binding to Data Source and click Next.

  4. On the final page, specify the data source table..

    DataSourceConfigurationWizard_AdoNet_SelectTable

    .. and click Finish.

  5. The Data Source Configuration Wizard generates the following code:

    using System.Data.Entity;
    using System.Windows.Forms;
    // ...
    public Form1()
    {
        InitializeComponent();
        // This line of code is generated by Data Source Configuration Wizard
        // Instantiate a new DBContext
        LinqToSqlServerModeExample.NWEntities1 dbContext = new LinqToSqlServerModeExample.NWEntities1();
        // Call the Load method to get the data for the given DbSet from the database.
        dbContext.Invoices.Load();
        // This line of code is generated by Data Source Configuration Wizard
        pivotGridControl1.DataSource = dbContext.Invoices.Local.ToBindingList();
    }
    
See Also