diff --git a/Dapper.SqlBuilder/Readme.md b/Dapper.SqlBuilder/Readme.md index ea69d9b80..5a0968f9f 100644 --- a/Dapper.SqlBuilder/Readme.md +++ b/Dapper.SqlBuilder/Readme.md @@ -85,10 +85,16 @@ var count = conn.ExecuteScalar(countTemplate.RawSql, countTemplate.Paramete Limitations and caveats -------- -OrWhere use `and` not `or` to concat sql problem +### Combining the Where and OrWhere methods -[Issue 647](https://github.com/DapperLib/Dapper/issues/647) +The OrWhere method currently groups all `and` and `or` clauses by type, +then join the groups with `and` or `or` depending on the first call. +This may result in possibly unexpected outcomes. +See also [issue 647](https://github.com/DapperLib/Dapper/issues/647). +#### Example Where first + +When providing the following clauses ```csharp sql.Where("a = @a1"); sql.OrWhere("b = @b1"); @@ -97,11 +103,26 @@ sql.OrWhere("b = @b2"); ``` SqlBuilder will generate sql -```sql= -a = @a1 AND b = @b1 AND a = @a2 AND b = @b2 +```sql +a = @a1 AND a = @a2 AND ( b = @b1 OR b = @b2 ) ``` -not +and not say ```sql a = @a1 OR b = @b1 AND a = @a2 OR b = @b2 ``` + +#### Example OrWhere first + +When providing the following clauses +```csharp +sql.OrWhere("b = @b1"); +sql.Where("a = @a1"); +sql.OrWhere("b = @b2"); +sql.Where("a = @a2"); +``` + +SqlBuilder will generate sql +```sql +a = @a1 OR a = @a2 OR ( b = @b1 OR b = @b2 ) +```