Binding to a Data Source Using Entity Framework
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
Drag the EntityServerModeSource component and drop it onto the Page.
- Specify the type of objects retrieved from a data source, using the EntityServerModeDataSource.ContextTypeName property.
- Specify the data table name using the EntityServerModeDataSource.TableName property.
- Bind the Pivot Grid control to the EntityServerModeDataSource 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.
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;
}
See Also