Back to Devexpress

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

aspnet-116444-components-pivot-grid-binding-to-data-database-server-mode-binding-to-a-data-source-using-linq-to-sql-classes.md

latest2.7 KB
Original Source

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

  • Jun 21, 2024
  • 2 minutes to read

To enable server mode, you need to create an appropriate 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

  • Add LINQ to SQL Classes to the project.

  • 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 topic.

Binding the ASPxPivotGrid control to the LinqServerModeSource component

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

csharp
using DevExpress.Data.Linq;

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

Protected Sub LinqServerModeDataSource1_Selecting(ByVal sender As Object, ByVal e As LinqServerModeDataSourceSelectEventArgs)
    e.KeyExpression = "OrderID"
    e.QueryableSource = New ASP.NETLinqServerMode.DataClasses1DataContext().SalesPersons
End Sub

See Also

Binding to a Data Source Using Entity Framework