mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 增加 IUpdate.SetDto 根据 dto 更新的方法;#218
This commit is contained in:
parent
f22f65fee9
commit
5cff594161
@ -110,6 +110,13 @@
|
|||||||
清空状态数据
|
清空状态数据
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:FreeSql.DbSet`1.RemoveAsync(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
|
||||||
|
<summary>
|
||||||
|
根据 lambda 条件删除数据
|
||||||
|
</summary>
|
||||||
|
<param name="predicate"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:FreeSql.DbSet`1.Add(`0)">
|
<member name="M:FreeSql.DbSet`1.Add(`0)">
|
||||||
<summary>
|
<summary>
|
||||||
添加
|
添加
|
||||||
|
@ -2000,6 +2000,17 @@
|
|||||||
<param name="parms">参数</param>
|
<param name="parms">参数</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:FreeSql.IUpdate`1.SetDto(System.Object)">
|
||||||
|
<summary>
|
||||||
|
设置更新的列
|
||||||
|
<para></para>
|
||||||
|
SetDto(new { title = "xxx", clicks = 2 })
|
||||||
|
<para></para>
|
||||||
|
SetDto(new Dictionary<string, object> { ["title"] = "xxx", ["clicks"] = 2 })
|
||||||
|
</summary>
|
||||||
|
<param name="dto">dto 或 Dictionary<string, object></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:FreeSql.IUpdate`1.Where(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
|
<member name="M:FreeSql.IUpdate`1.Where(System.Linq.Expressions.Expression{System.Func{`0,System.Boolean}})">
|
||||||
<summary>
|
<summary>
|
||||||
lambda表达式条件,仅支持实体基础成员(不包含导航对象)<para></para>
|
lambda表达式条件,仅支持实体基础成员(不包含导航对象)<para></para>
|
||||||
|
@ -56,6 +56,7 @@ namespace FreeSql
|
|||||||
/// <param name="source">实体集合</param>
|
/// <param name="source">实体集合</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IUpdate<T1> SetSource(IEnumerable<T1> source);
|
IUpdate<T1> SetSource(IEnumerable<T1> source);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 忽略的列,IgnoreColumns(a => a.Name) | IgnoreColumns(a => new{a.Name,a.Time}) | IgnoreColumns(a => new[]{"name","time"})
|
/// 忽略的列,IgnoreColumns(a => a.Name) | IgnoreColumns(a => new{a.Name,a.Time}) | IgnoreColumns(a => new[]{"name","time"})
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -107,6 +108,17 @@ namespace FreeSql
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IUpdate<T1> SetRaw(string sql, object parms = null);
|
IUpdate<T1> SetRaw(string sql, object parms = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置更新的列
|
||||||
|
/// <para></para>
|
||||||
|
/// SetDto(new { title = "xxx", clicks = 2 })
|
||||||
|
/// <para></para>
|
||||||
|
/// SetDto(new Dictionary<string, object> { ["title"] = "xxx", ["clicks"] = 2 })
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dto">dto 或 Dictionary<string, object></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
IUpdate<T1> SetDto(object dto);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// lambda表达式条件,仅支持实体基础成员(不包含导航对象)<para></para>
|
/// lambda表达式条件,仅支持实体基础成员(不包含导航对象)<para></para>
|
||||||
/// 若想使用导航对象,请使用 ISelect.ToUpdate() 方法
|
/// 若想使用导航对象,请使用 ISelect.ToUpdate() 方法
|
||||||
|
@ -334,26 +334,31 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void SetPriv(ColumnInfo col, object value)
|
||||||
|
{
|
||||||
|
object paramVal = null;
|
||||||
|
if (value != null)
|
||||||
|
{
|
||||||
|
if (col.Attribute.MapType == value.GetType()) paramVal = value;
|
||||||
|
else paramVal = Utils.GetDataReaderValue(col.Attribute.MapType, value);
|
||||||
|
}
|
||||||
|
_set.Append(", ").Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append(" = ");
|
||||||
|
if (_noneParameter)
|
||||||
|
{
|
||||||
|
_set.Append(_commonUtils.GetNoneParamaterSqlValue(_params, col.Attribute.MapType, paramVal));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_set.Append(_commonUtils.QuoteWriteParamter(col.Attribute.MapType, $"{_commonUtils.QuoteParamterName("p_")}{_params.Count}"));
|
||||||
|
_commonUtils.AppendParamter(_params, null, col, col.Attribute.MapType, paramVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
public IUpdate<T1> Set<TMember>(Expression<Func<T1, TMember>> column, TMember value)
|
public IUpdate<T1> Set<TMember>(Expression<Func<T1, TMember>> column, TMember value)
|
||||||
{
|
{
|
||||||
var cols = new List<SelectColumnInfo>();
|
var cols = new List<SelectColumnInfo>();
|
||||||
_commonExpression.ExpressionSelectColumn_MemberAccess(null, cols, SelectTableInfoType.From, column?.Body, true, null);
|
_commonExpression.ExpressionSelectColumn_MemberAccess(null, cols, SelectTableInfoType.From, column?.Body, true, null);
|
||||||
if (cols.Count != 1) return this;
|
if (cols.Count != 1) return this;
|
||||||
var col = cols.First();
|
SetPriv(cols.First().Column, value);
|
||||||
object paramVal = null;
|
|
||||||
if (col.Column.Attribute.MapType == typeof(TMember)) paramVal = value;
|
|
||||||
else paramVal = Utils.GetDataReaderValue(col.Column.Attribute.MapType, value);
|
|
||||||
_set.Append(", ").Append(_commonUtils.QuoteSqlName(col.Column.Attribute.Name)).Append(" = ");
|
|
||||||
if (_noneParameter)
|
|
||||||
{
|
|
||||||
_set.Append(_commonUtils.GetNoneParamaterSqlValue(_params, col.Column.Attribute.MapType, paramVal));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_set.Append(_commonUtils.QuoteWriteParamter(col.Column.Attribute.MapType, $"{_commonUtils.QuoteParamterName("p_")}{_params.Count}"));
|
|
||||||
_commonUtils.AppendParamter(_params, null, col.Column, col.Column.Attribute.MapType, paramVal);
|
|
||||||
}
|
|
||||||
//foreach (var t in _source) Utils.FillPropertyValue(t, tryf.CsName, value);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public IUpdate<T1> Set<TMember>(Expression<Func<T1, TMember>> exp)
|
public IUpdate<T1> Set<TMember>(Expression<Func<T1, TMember>> exp)
|
||||||
@ -424,6 +429,27 @@ namespace FreeSql.Internal.CommonProvider
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IUpdate<T1> SetDto(object dto)
|
||||||
|
{
|
||||||
|
if (dto == null) return this;
|
||||||
|
if (dto is Dictionary<string, object>)
|
||||||
|
{
|
||||||
|
var dic = dto as Dictionary<string, object>;
|
||||||
|
foreach (var kv in dic)
|
||||||
|
{
|
||||||
|
if (_table.ColumnsByCs.TryGetValue(kv.Key, out var trycol) == false) continue;
|
||||||
|
SetPriv(trycol, kv.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var dtoProps = dto.GetType().GetProperties();
|
||||||
|
foreach (var dtoProp in dtoProps)
|
||||||
|
{
|
||||||
|
if (_table.ColumnsByCs.TryGetValue(dtoProp.Name, out var trycol) == false) continue;
|
||||||
|
SetPriv(trycol, dtoProp.GetValue(dto, null));
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public IUpdate<T1> Where(Expression<Func<T1, bool>> expression) => this.Where(_commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, expression?.Body, null, _params));
|
public IUpdate<T1> Where(Expression<Func<T1, bool>> expression) => this.Where(_commonExpression.ExpressionWhereLambdaNoneForeignObject(null, _table, null, expression?.Body, null, _params));
|
||||||
public IUpdate<T1> Where(string sql, object parms = null)
|
public IUpdate<T1> Where(string sql, object parms = null)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user