Skip to content

Commit

Permalink
- 完善 IDelete WhereIf(bool, sql) 方法;
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Dec 7, 2020
1 parent 671fb09 commit ff1354d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 185 deletions.
193 changes: 10 additions & 183 deletions FreeSql/FreeSql.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions FreeSql/Interface/Curd/IDelete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ public interface IDelete<T1>
/// <returns></returns>
IDelete<T1> Where(string sql, object parms = null);
/// <summary>
/// 原生sql语法条件,Where("id = @id", new { id = 1 })<para></para>
/// 提示:parms 参数还可以传 Dictionary&lt;string, object&gt;
/// </summary>
/// <param name="condition">true 时生效</param>
/// <param name="sql">sql语法条件</param>
/// <param name="parms">参数</param>
/// <returns></returns>
IDelete<T1> WhereIf(bool condition, string sql, object parms = null);
/// <summary>
/// 传入实体,将主键作为条件
/// </summary>
/// <param name="item">实体</param>
Expand Down
5 changes: 3 additions & 2 deletions FreeSql/Internal/CommonProvider/DeleteProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ public IDelete<T1> WhereIf(bool condition, Expression<Func<T1, bool>> exp)
if (condition == false || exp == null) return this;
return this.Where(_commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, exp?.Body, null, _params));
}
public IDelete<T1> Where(string sql, object parms = null)
public IDelete<T1> Where(string sql, object parms = null) => WhereIf(true, sql, parms);
public IDelete<T1> WhereIf(bool condition, string sql, object parms = null)
{
if (string.IsNullOrEmpty(sql)) return this;
if (condition == false || string.IsNullOrEmpty(sql)) return this;
if (++_whereTimes > 1) _where.Append(" AND ");
_where.Append('(').Append(sql).Append(')');
if (parms != null) _params.AddRange(_commonUtils.GetDbParamtersByObject(sql, parms));
Expand Down

0 comments on commit ff1354d

Please sign in to comment.