UpdateableProviderT4.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq.Expressions;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Linq;
  7. namespace SqlSugar
  8. {
  9. public class UpdateableProvider<T, T2, T3, T4> : IUpdateable<T, T2, T3, T4> where T : class, new()
  10. {
  11. public IUpdateable<T> updateableObj { get; set; }
  12. public int ExecuteCommand()
  13. {
  14. return this.updateableObj.ExecuteCommand();
  15. }
  16. public Task<int> ExecuteCommandAsync()
  17. {
  18. return this.updateableObj.ExecuteCommandAsync();
  19. }
  20. public IUpdateable<T, T2, T3, T4> SetColumns(Expression<Func<T, T2, T3, T4, T>> columns)
  21. {
  22. updateableObj.UpdateBuilder.Context.InitMappingInfo<T4>();
  23. var exp = ((columns as LambdaExpression).Body as MemberInitExpression).Bindings;
  24. var items = ExpressionTool.GetMemberBindingItemList(exp);
  25. var UpdateBuilder = updateableObj.UpdateBuilder;
  26. var SqlBuilder = UpdateBuilder.Builder;
  27. foreach (var item in items)
  28. {
  29. var dbColumnName = updateableObj.UpdateBuilder.Context.EntityMaintenance.GetDbColumnName<T>(item.Key);
  30. var value = updateableObj.UpdateBuilder.GetExpressionValue(ExpressionTool.RemoveConvert(item.Value), ResolveExpressType.WhereMultiple).GetString();
  31. this.updateableObj.UpdateBuilder.SetValues.Add(new KeyValuePair<string, string>(dbColumnName, value));
  32. }
  33. UpdateBuilder.DbColumnInfoList = UpdateBuilder.DbColumnInfoList
  34. .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();
  35. return this;
  36. }
  37. public IUpdateable<T, T2, T3, T4> Where(Expression<Func<T, T2, T3, T4, bool>> whereExpression)
  38. {
  39. var value = updateableObj.UpdateBuilder.GetExpressionValue(whereExpression, ResolveExpressType.WhereMultiple).GetString();
  40. updateableObj.UpdateBuilder.WhereValues.Add(value);
  41. return this;
  42. }
  43. }
  44. }