Files
SqlSugar/Src/Asp.NetCore2/SqlSugar/Abstract/UpdateProvider/UpdateableProviderT4.cs

48 lines
2.2 KiB
C#
Raw Normal View History

2023-04-24 12:59:00 +08:00
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
2023-04-24 16:34:56 +08:00
using System.Linq;
2023-04-24 12:59:00 +08:00
namespace SqlSugar
{
2023-04-24 16:34:56 +08:00
public class UpdateableProvider<T, T2, T3, T4> : IUpdateable<T, T2, T3, T4> where T : class, new()
2023-04-24 12:59:00 +08:00
{
2023-04-24 16:34:56 +08:00
public IUpdateable<T> updateableObj { get; set; }
2023-04-24 12:59:00 +08:00
public int ExecuteCommand()
{
2023-04-24 16:34:56 +08:00
return this.updateableObj.ExecuteCommand();
2023-04-24 12:59:00 +08:00
}
public Task<int> ExecuteCommandAsync()
{
2023-04-24 16:34:56 +08:00
return this.updateableObj.ExecuteCommandAsync();
2023-04-24 12:59:00 +08:00
}
public IUpdateable<T, T2, T3, T4> SetColumns(Expression<Func<T, T2, T3, T4, T>> columns)
{
2023-04-24 16:34:56 +08:00
var exp = ((columns as LambdaExpression).Body as MemberInitExpression).Bindings;
var items = ExpressionTool.GetMemberBindingItemList(exp);
var UpdateBuilder = updateableObj.UpdateBuilder;
var SqlBuilder = UpdateBuilder.Builder;
foreach (var item in items)
{
var dbColumnName = updateableObj.UpdateBuilder.Context.EntityMaintenance.GetDbColumnName<T>(item.Key);
var value = updateableObj.UpdateBuilder.GetExpressionValue(ExpressionTool.RemoveConvert(item.Value), ResolveExpressType.WhereMultiple).GetString();
this.updateableObj.UpdateBuilder.SetValues.Add(new KeyValuePair<string, string>(dbColumnName, value));
}
UpdateBuilder.DbColumnInfoList = UpdateBuilder.DbColumnInfoList
.Where(it => it.UpdateServerTime == true || it.UpdateSql.HasValue() || UpdateBuilder.SetValues.Any(v => SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase) || SqlBuilder.GetNoTranslationColumnName(v.Key).Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase)) || it.IsPrimarykey == true).ToList();
return this;
2023-04-24 12:59:00 +08:00
}
public IUpdateable<T, T2, T3, T4> Where(Expression<Func<T, T2, T3, T4, bool>> whereExpression)
{
2023-04-24 16:34:56 +08:00
var value = updateableObj.UpdateBuilder.GetExpressionValue(whereExpression, ResolveExpressType.WhereMultiple).GetString();
updateableObj.UpdateBuilder.WhereValues.Add(value);
return this;
2023-04-24 12:59:00 +08:00
}
}
}