Skip to content

Commit ff1354d

Browse files
committed
- 完善 IDelete WhereIf(bool, sql) 方法;
1 parent 671fb09 commit ff1354d

File tree

3 files changed

+22
-185
lines changed

3 files changed

+22
-185
lines changed

FreeSql/FreeSql.xml

Lines changed: 10 additions & 183 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FreeSql/Interface/Curd/IDelete.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ public interface IDelete<T1>
5353
/// <returns></returns>
5454
IDelete<T1> Where(string sql, object parms = null);
5555
/// <summary>
56+
/// 原生sql语法条件,Where("id = @id", new { id = 1 })<para></para>
57+
/// 提示:parms 参数还可以传 Dictionary&lt;string, object&gt;
58+
/// </summary>
59+
/// <param name="condition">true 时生效</param>
60+
/// <param name="sql">sql语法条件</param>
61+
/// <param name="parms">参数</param>
62+
/// <returns></returns>
63+
IDelete<T1> WhereIf(bool condition, string sql, object parms = null);
64+
/// <summary>
5665
/// 传入实体,将主键作为条件
5766
/// </summary>
5867
/// <param name="item">实体</param>

FreeSql/Internal/CommonProvider/DeleteProvider.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ public IDelete<T1> WhereIf(bool condition, Expression<Func<T1, bool>> exp)
9898
if (condition == false || exp == null) return this;
9999
return this.Where(_commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, exp?.Body, null, _params));
100100
}
101-
public IDelete<T1> Where(string sql, object parms = null)
101+
public IDelete<T1> Where(string sql, object parms = null) => WhereIf(true, sql, parms);
102+
public IDelete<T1> WhereIf(bool condition, string sql, object parms = null)
102103
{
103-
if (string.IsNullOrEmpty(sql)) return this;
104+
if (condition == false || string.IsNullOrEmpty(sql)) return this;
104105
if (++_whereTimes > 1) _where.Append(" AND ");
105106
_where.Append('(').Append(sql).Append(')');
106107
if (parms != null) _params.AddRange(_commonUtils.GetDbParamtersByObject(sql, parms));

0 commit comments

Comments
 (0)