Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions Dapper.SqlBuilder/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,16 @@ var count = conn.ExecuteScalar<int>(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");
Expand All @@ -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 )
```