Skip to content

.Take(0) returns all records #766

Open

Description

@davehauser

From the Docs:

If you are coming from a Linq background here is a bonus for you. You can use the Skip and Take methods as aliases for Offset and Limit enjoy :)

Coming from Linq I would expect the following query to return all records for authorized = true and zero records if authorized = false.

var query = authorized
  ? new Query("Items")
  : new Query("Items).Take(0);

In fact, however, SqlKata generates the same SQL code from both queries:

SELECT
  *
FROM
  [Items]

As stated in the documentation, the Take method is merely an alias for Limit, so 0 is treated as “no limit.” Regarding Limit, this also makes sense from a linguistic point of view: zero limit = no limit. With Take, on the other hand, this is very misleading: take zero ≠ take everything

Changing the Take method to treat 0 as zero would, of course, be a fundamental change and a delicate one as well (and also a breaking change). But at the same time, it would make the API more precise and easier to understand.

Activity

  1. ahmad-moussawi commented on Oct 31, 2025

    @ahmad-moussawi
    Contributor

    You have a point here, this is a breaking change though, so worth discussing it further,
    but for your use case, I would set a falsy where condition instead of limit, Limit() can be easily overriden, i.e. if you are wrapping your query with some logic to handle pagination, etc..., while this is not the case for .WhereRaw("1 = 0").

    So my suggestion would be to always restrict your queries by a falsy where instead.

    query.WhenNot(authorized, q => q.WhereRaw("1 = 0"))

    Note: be aware of top level or conditions though, anyway it's a bad practice to have top-level or conditions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions