- 增加 IUpdate.SetIf 方法;#309

This commit is contained in:
28810 2020-05-13 16:52:12 +08:00
parent 2853c356e6
commit a0acece7e5
2 changed files with 21 additions and 0 deletions

View File

@ -93,6 +93,15 @@ namespace FreeSql
/// <returns></returns>
IUpdate<T1> Set<TMember>(Expression<Func<T1, TMember>> column, TMember value);
/// <summary>
/// 设置列的新值Set(a => a.Name, "newvalue")
/// </summary>
/// <typeparam name="TMember"></typeparam>
/// <param name="condition">true 时生效</param>
/// <param name="column">lambda选择列</param>
/// <param name="value">新值</param>
/// <returns></returns>
IUpdate<T1> SetIf<TMember>(bool condition, Expression<Func<T1, TMember>> column, TMember value);
/// <summary>
/// 设置列的的新值为基础上增加格式Set(a => a.Clicks + 1) 相当于 clicks=clicks+1
/// <para></para>
/// 指定更新格式Set(a => new T { Clicks = a.Clicks + 1, Time = DateTime.Now }) 相当于 set clicks=clicks+1,time='2019-06-19....'
@ -102,6 +111,16 @@ namespace FreeSql
/// <returns></returns>
IUpdate<T1> Set<TMember>(Expression<Func<T1, TMember>> exp);
/// <summary>
/// 设置列的的新值为基础上增加格式Set(a => a.Clicks + 1) 相当于 clicks=clicks+1
/// <para></para>
/// 指定更新格式Set(a => new T { Clicks = a.Clicks + 1, Time = DateTime.Now }) 相当于 set clicks=clicks+1,time='2019-06-19....'
/// </summary>
/// <typeparam name="TMember"></typeparam>
/// <param name="condition">true 时生效</param>
/// <param name="exp"></param>
/// <returns></returns>
IUpdate<T1> SetIf<TMember>(bool condition, Expression<Func<T1, TMember>> exp);
/// <summary>
/// 设置值自定义SQL语法SetRaw("title = ?title", new { title = "newtitle" })
/// </summary>
/// <param name="sql">sql语法</param>

View File

@ -400,6 +400,7 @@ namespace FreeSql.Internal.CommonProvider
SetPriv(cols.First().Column, value);
return this;
}
public IUpdate<T1> SetIf<TMember>(bool condition, Expression<Func<T1, TMember>> column, TMember value) => condition ? Set(column, value) : this;
public IUpdate<T1> Set<TMember>(Expression<Func<T1, TMember>> exp)
{
var body = exp?.Body;
@ -459,6 +460,7 @@ namespace FreeSql.Internal.CommonProvider
_setIncr.Append(", ").Append(_commonUtils.QuoteSqlName(cols.First().Column.Attribute.Name)).Append(" = ").Append(expt);
return this;
}
public IUpdate<T1> SetIf<TMember>(bool condition, Expression<Func<T1, TMember>> exp) => condition ? Set(exp) : this;
public IUpdate<T1> SetRaw(string sql, object parms = null)
{
if (string.IsNullOrEmpty(sql)) return this;