mrahhal / MR.EntityFrameworkCore.KeysetPagination

Keyset/Seek/Cursor pagination for Entity Framework Core.
MIT License
218 stars 11 forks source link

Extend builder to pass member access by dot '.' notation string #31

Closed CaminGui closed 1 year ago

CaminGui commented 1 year ago

As a developer I want to be able to specify member to acces using string dot '.' notation.

Our frontend just send to us the member path to order on in dot notation form.

This also ease the way we access Json fields in our backend.

public class NestedJsonModel
{
    public int Id { get; set; }
    public NestedInnerJsonModel Inner { get; set; }
}

public class NestedInnerJsonModel
{
    public int Id { get; set; }
    public DateTime Created { get; set; }
    public JsonDocument Data { get; set; }
}

var context = query..KeysetPaginateQuery(
            b => b.Ascending("inner.data.nbString"),
            KeysetPaginationDirection.Forward);

For Json property we also need an extra parameter to convert the JsonElement to the value type.

It can also be use in other cases for type convertion.

MethodInfo converter = typeof(JsonElement).GetMethod(....);
var context = query..KeysetPaginateQuery(
            b => b.Ascending("inner.data.nbString", converter),
            KeysetPaginationDirection.Forward);
mrahhal commented 1 year ago

I'm hesitant about this as well. Not having proper indexing completely defeats the point of doing keyset pagination. Your code snippet above is saying you can create a keyset out of anything and everything, which doesn't really make sense.

If you have well known cases (which you can index properly), then I recommend your frontend send some kind of enum (or whatever you like) that identifies which case you want, and then switch on that and build your keyset. Having this dynamic string support will encourage creating keysets out of anything, which is something I don't want.