Back to Devexpress

Binding to a Data Source Using Entity Framework

aspnet-116445-components-pivot-grid-binding-to-data-database-server-mode-binding-to-a-data-source-using-entity-framework.md

latest2.5 KB
Original Source

Binding to a Data Source Using Entity Framework

  • Dec 17, 2020

This example shows how to generate model and mapping information and bind the pivot grid to the data source using Entity Framework.

Creating Data Classes

  • Add ADO.NET Entity Data Model to the project.

  • Follow the wizard steps to generate a new data model using the code-first or database-first development approach.

  • Save the generated model, close the EDMX diagram, and rebuild the solution

Binding the ASPxPivotGrid control to the EntityServerModeSource component

If the database table that is used to generate a EDMX diagram does not have a primary key, handle the EntityServerModeDataSource.Selecting event and specify the LinqServerModeDataSourceSelectEventArgs.KeyExpression and LinqServerModeDataSourceSelectEventArgs.QueryableSource properties.

csharp
using DevExpress.Data.Linq;

protected void EntityServerModeDataSource1_Selecting(object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e)
{
    e.KeyExpression = "OrderID";
    e.QueryableSource = new ASP.NETEntityServerMode.NWindEntities().SalesPersons;
}
vb
Imports DevExpress.Data.Linq

Protected Sub EntityServerModeDataSource1_Selecting(ByVal sender As Object, ByVal e As DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs)
    e.KeyExpression = "OrderID"
    e.QueryableSource = New ASP.NETEntityServerMode.NWindEntities().SalesPersons
End Sub

See Also

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