mrahhal / MR.EntityFrameworkCore.KeysetPagination

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

Support JsonElement property access for Postgres #30

Closed CaminGui closed 1 year ago

CaminGui commented 1 year ago

As a developer I want to be able to use a Json property in the keyset.

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(x => x.Inner.Data.RootElement.GetProperty("nbString").GetString()),
            KeysetPaginationDirection.Forward);
mrahhal commented 1 year ago

I'm not sure this is something I want to add on the level of the core library. This is tied to a particular json lib (System.Text.Json) and/or a database (postgres). This is a very uncommon usage in the first place, and it already has a workaround. You can always use a computed column for the particular json field you include, and use that in the keyset. This works with any json lib, with any db.