DapperLib / DapperLib/Dapper

SQLBuilder how to define multiple OR conditions?

Open
#1,240 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

area:sqlbuilder
Dominant language
C#
Stars
18.4k
Forks
3.7k
Avg merge
5h 8m
Merged PRs (30d)
1

Description

This is a really handy utility for building dynamic SQL in Dapper but I can't figure out how to do this.

SQL I want would be something like this:

SELECT * FROM Product WHERE (Color = "Red" OR Color = "Black") AND (Price > 100 OR Quantity > 3)

The issue is that it just aggregates all the ANDs together and all the ORs together. Assuming there is no way to do this currently would it be possible to have a mechanism to do this by passing a null to the Where( ) method? So for example:

sqlBuilder.OrWhere("Color = @p1", new { p1 = "Red" });
sqlBuilder.OrWhere("Color = @p2", new { p2 = "Black"});
sqlBuilder.Where(null); //or sqlBuilder.Where("AND") maybe? 
sqlBuilder.OrWhere("Price > @p3", new { p3 = 100 });
sqlBuilder.OrWhere("Quantity > @p4", new { p4 = 3});

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating SQLBuilder and its Where and OrWhere methods, then inspect how conditions and parameters are currently aggregated. Define the grouping behavior needed for the two parenthesized OR expressions and verify it with a test matching the SQL example; done means grouped conditions produce the intended AND/OR structure.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql
Domain
database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.