Skip to content

Enhancement: Add RepoDb.Options - options-object overloads for all Operations #1326

Open

Description

@mikependon

Describe the enhancement

In the current implementation of the library, most of IDbConnection (and BaseRepository/DbRepository) operations - Query, Insert, Update, Delete and Merge - accept a long list of optional arguments (fields, orderBy, top, hints, cacheKey, cacheItemExpiration, commandTimeout, traceKey, transaction, cache, trace, statementBuilder, etc).

As call sites grow, these long parameter lists become hard to read, hard to maintain, and easy to get wrong when only a couple of the values actually need to be set.

This enhancement proposes RepoDb.Options, a companion package that adds overloads accepting a single strongly-typed options object instead. For example, for Query:

// Before
var products = connection.Query<Product>(
    where: p => p.CategoryId == 1,
    fields: Field.From("Id", "Name", "Price"),
    orderBy: OrderField.Parse(new { Name = Order.Ascending }),
    top: 10,
    hints: "WITH (NOLOCK)",
    cacheKey: "products-category-1",
    cacheItemExpiration: 30,
    commandTimeout: 120,
    traceKey: TraceKeys.Query,
    transaction: transaction,
    cache: cache,
    trace: trace,
    statementBuilder: statementBuilder);

// After
var products = connection.Query<Product>(
    where: p => p.CategoryId == 1,
    options: new ConnectionQueryOptions
    {
        Fields = Field.From("Id", "Name", "Price"),
        OrderBy = OrderField.Parse(new { Name = Order.Ascending }),
        Top = 10,
        Hints = "WITH (NOLOCK)",
        CacheKey = "products-category-1",
        CacheItemExpiration = 30,
        CommandTimeout = 120,
        Transaction = transaction,
        Cache = cache,
        Trace = trace,
        StatementBuilder = statementBuilder
    });

The same options overload is available on BaseRepository<TEntity, TDbConnection> and DbRepository<TDbConnection> via a matching RepositoryQueryOptions object:

var products = repository.Query<Product>(
    where: p => p.CategoryId == 1,
    options: new RepositoryQueryOptions
    {
        Fields = Field.From("Id", "Name", "Price"),
        OrderBy = OrderField.Parse(new { Name = Order.Ascending }),
        Top = 10,
        Hints = "WITH (NOLOCK)",
        CacheKey = "products-category-1",
        Transaction = transaction
    });

The same pattern extends to Insert, Update, Delete and Merge via ConnectionInsertOptions/RepositoryInsertOptions, ConnectionUpdateOptions/RepositoryUpdateOptions, ConnectionDeleteOptions/RepositoryDeleteOptions and ConnectionMergeOptions/RepositoryMergeOptions, keeping the same options-object shape across the whole surface.

Additional Context

  • New package: RepoDb.Options (targets net8.0, net9.0, net10.0 and netstandard2.0).
  • Lives under src/Options/RepoDb.Options, referencing RepoDb.Core.
  • Purely additive: all existing positional/named-parameter overloads remain unchanged, these are extra overloads, not replacements.
  • Each options object defaults sensibly when null (e.g. options ??= new ConnectionQueryOptions()), so it's a drop-in alternative rather than a required migration.
  • Goal is a more readable, discoverable, and IntelliSense-friendly call site for operations with many optional settings, especially as new optional settings get added over time.

Activity

  1. added
    enhancement
    request
    for grabs
    on Sep 9, 2026
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

    enhancementfor grabsrequest

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions