Преглед изворни кода

!1046 表单提交使用IgnoreColumns 出现无法保存为的问题
Merge pull request !1046 from aquan/N/A

zuohuaijun пре 2 година
родитељ
комит
c3a38030a6
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;
+   }
 }