Home > Blockchain >  Data source for DevExpress GridControl with paging, sorting, filtering, grouping
Data source for DevExpress GridControl with paging, sorting, filtering, grouping

Time:10-12

What data source can we use so that we can get data from SQL Server and display it in a DevExpress GridControl (in WinForms)? It needs to work with .NET 6 and provide automatic paging, sorting, filtering and grouping at the SQL query level.

What we had when we used .NET Framework 4.7 was a LinqServerModeSource connected to a DataContext table:

using System.Data.Linq;

linqServerModeSource.QueryableSource = new DataContext(connectionString).GetTable(typeof(Persons));
gridPersons.DataSource = linqServerModeSource;

but in .NET 6 the namespace System.Data.Linq does not exist anymore.

CodePudding user response:

You need to make an OData API endpoint for the DevExpress component. LINQ/EF magic will then transpile the OData queries from DefExpress to SQL.

The return type of the controller action will be IQueryable and IIRC you need to add the [Queryable] attribute -- but webAPI is such a moving target that they've probably changed it all since I last did it.

The IQueryable in questin will be an entity set (or a LINQ expression on entity sets) in your db context. If your basic query is quite complicated then you might prefer to make a view for it and map that to an entity set.

This all means that the query for your underlying dataset is known at compile time...

CodePudding user response:

I ended up using EntityServerModeSource in conjunction with Entity Framework Core DbContext and DbSet:

entityServerModeSource.QueryableSource = myDbContext.PersonsDbSet;
entityServerModeSource.KeyExpression = "Id";
entityServerModeSource.Reload();
gridPersons.DataSource = entityServerModeSource;
  • Related