PawelGerr / Thinktecture.EntityFrameworkCore

These libraries extend Entity Framework Core by a few features to make it easier to work with EF and for easier integration testing or to get more performance in some special cases.
https://dev.azure.com/pawelgerr/Thinktecture.EntityFrameworkCore
BSD 3-Clause "New" or "Revised" License
66 stars 17 forks source link

[FeatureRequest] RowNumber overload without RowNumberOrderByClause #13

Open Liero opened 3 years ago

Liero commented 3 years ago

I want to add RowNumbers to IOrderedQueryable<TEntity>.

The problem is, that constructing RowNumberOrderByClause dynamically is not a trivial task.

I think following overload would be useful:

var query = dbContext.Products;
var orderedQuery = ApplyOrderBy(query, DataGrid.SortModel);
orderedQuery.Select(entity => new {
   entity,
   rowNumber = EF.Functions.RowNumber(entity)
})

alternativelly:

RowNumberOrderByClause FromOrderedQueryable<TEntity>(IOrderedQueryable<TEntity> query);

orderedQuery.Select(entity => new {
   entity,
   rowNumber = EF.Functions.RowNumber(RowNumberOrderByClause.FromOrderedQueryable(query))
})

Simmilar approach was mentioned here #7

EDIT:

or even better this Select overload:

orderedQuery.Select((entity, index) => new { entity, index });
PawelGerr commented 2 years ago

Hi, the last idea (Select((entity, index) => )) looks interessting but currently I have no time to implement this feature.