Skip to content

Commit 5e12586

Browse files
Merge pull request #202 from sqlkata/when_not
add when not
2 parents 5ef5693 + abed098 commit 5e12586

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

QueryBuilder/Query.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,19 @@ public Query Distinct()
194194
/// Apply the callback's query changes if the given "condition" is true.
195195
/// </summary>
196196
/// <param name="condition"></param>
197-
/// <param name="callback"></param>
197+
/// <param name="whenTrue">Invoked when the condition is true</param>
198+
/// <param name="whenFalse">Optional, invoked when the condition is false</param>
198199
/// <returns></returns>
199-
public Query When(bool condition, Func<Query, Query> callback)
200+
public Query When(bool condition, Func<Query, Query> whenTrue, Func<Query, Query> whenFalse = null)
200201
{
201-
if (condition)
202+
if (condition && whenTrue != null)
202203
{
203-
return callback.Invoke(this);
204+
return whenTrue.Invoke(this);
205+
}
206+
207+
if (!condition && whenFalse != null)
208+
{
209+
return whenFalse.Invoke(this);
204210
}
205211

206212
return this;

0 commit comments

Comments
 (0)