Skip to content

Commit

Permalink
SqlBuilderCore新增Append、AppendIf方法;
Browse files Browse the repository at this point in the history
  • Loading branch information
zqlovejyc committed Oct 23, 2020
1 parent e111b6d commit 9bbfb34
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions SQLBuilder/Entry/SqlBuilderCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4229,6 +4229,96 @@ public SqlBuilderCore<T> Distinct()
}
#endregion

#region Append
/// <summary>
/// Append
/// </summary>
/// <param name="sql">自定义sql语句</param>
/// <returns>SqlBuilderCore</returns>
public SqlBuilderCore<T> Append(string sql)
{
this.sqlWrapper += sql;
return this;
}

/// <summary>
/// Append
/// </summary>
/// <param name="sql">自定义sql语句</param>
/// <returns>SqlBuilderCore</returns>
public SqlBuilderCore<T> Append(StringBuilder sql)
{
this.sqlWrapper.Sql.Append(sql);
return this;
}
#endregion

#region AppendIf
/// <summary>
/// AppendIf
/// </summary>
/// <param name="condition">自定义条件</param>
/// <param name="sql">自定义sql语句</param>
/// <returns>SqlBuilderCore</returns>
public SqlBuilderCore<T> AppendIf(bool condition, string sql)
{
if (condition)
this.sqlWrapper += sql;

return this;
}

/// <summary>
/// AppendIf
/// </summary>
/// <param name="condition">自定义条件</param>
/// <param name="sql">自定义sql语句</param>
/// <param name="callback">回调委托</param>
/// <returns>SqlBuilderCore</returns>
public SqlBuilderCore<T> AppendIf(bool condition, string sql, Action callback)
{
if (condition)
{
this.sqlWrapper += sql;
callback?.Invoke();
}

return this;
}

/// <summary>
/// AppendIf
/// </summary>
/// <param name="condition">自定义条件</param>
/// <param name="sql">自定义sql语句</param>
/// <returns>SqlBuilderCore</returns>
public SqlBuilderCore<T> AppendIf(bool condition, StringBuilder sql)
{
if (condition)
this.sqlWrapper.Sql.Append(sql);

return this;
}

/// <summary>
/// AppendIf
/// </summary>
/// <param name="condition">自定义条件</param>
/// <param name="sql">自定义sql语句</param>
/// <param name="callback">回调委托</param>
/// <returns>SqlBuilderCore</returns>
public SqlBuilderCore<T> AppendIf(bool condition, StringBuilder sql, Action callback)
{
if (condition)
{
this.sqlWrapper.Sql.Append(sql);
callback?.Invoke();
}

return this;
}
#endregion

#region GetTableName
/// <summary>
/// 获取实体对应的表名
Expand Down

0 comments on commit 9bbfb34

Please sign in to comment.