Просмотр исходного кода

如果表单更新时忽略为Null 的规则(.IgnoreColumns(ignoreAllNullColumns: true)),会导致为Null( 例如时间控件,清除值后,后台无法保存) 的数据无法更新保存。故扩展了该方法

Signed-off-by: aquan <1491897341@qq.com>
aquan 2 лет назад
Родитель
Сommit
b96a2db78c
1 измененных файлов с 24 добавлено и 0 удалено
  1. 24 0
      Admin.NET/Admin.NET.Core/Extension/RepositoryExtension.cs

+ 24 - 0
Admin.NET/Admin.NET.Core/Extension/RepositoryExtension.cs

@@ -387,4 +387,28 @@ public static class RepositoryExtension
         }
         return new List<T>() { thisValue };
     }
+
+    /// <summary>
+    /// 只更新某些列
+    /// </summary>
+    /// <typeparam name="T"></typeparam>
+    /// <typeparam name="R"></typeparam>
+    /// <param name="updateable"></param>
+    /// <returns></returns>
+   public static IUpdateable<T> OnlyUpdateColumn<T,R>(this IUpdateable<T> updateable) where T : EntityBase, new() where R : class, new()
+   {
+      if (updateable.UpdateBuilder.UpdateColumns == null)
+      {
+          updateable.UpdateBuilder.UpdateColumns = new List<string>();
+      }
+      foreach (PropertyInfo info in typeof(R).GetProperties())
+      {
+          //判断是否是相同属性
+          PropertyInfo pro = typeof(T).GetProperty(info.Name);
+          if (pro != null)
+              updateable.UpdateBuilder.UpdateColumns.Add(info.Name);
+
+      }
+      return updateable;
+   }
 }