mrahhal / MR.EntityFrameworkCore.KeysetPagination

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

HasNextAsync returns false when it should be true for nullable column #56

Closed Konopnik closed 2 months ago

Konopnik commented 2 months ago

When there is desc order by nullable column + asc by id and it is called with reference with null value in nullable column HasNextAsync will return always false.

Here you have test which will fail:

[Fact]
    public async Task HasNext_WithDescendingNullableColumnWhereTheValueIsNull_ShouldBeTrue()
    {
        // The last page.
        var keysetContext = DbContext.MainModels.Where(x=>x.CreatedNullable == null).KeysetPaginate(
            b => b.Descending(x => x.CreatedNullable).Ascending(x => x.Id),
            KeysetPaginationDirection.Forward);
        var data = await keysetContext.Query
            .Take(1)
            .ToListAsync();
        keysetContext.EnsureCorrectOrder(data);

        // Next on the first item => should be true
        var hasNext = await keysetContext.HasNextAsync(data);

        hasNext.Should().BeTrue();
    }
mrahhal commented 2 months ago

Thanks for providing a test. Having a nullable column in the keyset is not supported as mentioned in caveats.md. The same link also includes more info about the reason and potential solutions. This library also ships with an analyzer that would have flagged nullable keysets as warnings, as it's impossible to reliably deal with DB nulls in a keyset.

mrahhal commented 2 months ago

I'm closing this, please reopen if you still have issues.