wyq 5 tháng trước cách đây
mục cha
commit
45cc681fc5

+ 7 - 3
DW5S.App/UserControl/CtrlRefTask.cs

@@ -7,6 +7,7 @@ using DW5S.Repostory;
 using DW5S.ViewModel;
 using DxHelper;
 using ExtensionsDev;
+using Google.Protobuf.WellKnownTypes;
 using Microsoft.EntityFrameworkCore;
 using System;
 using System.Collections.Generic;
@@ -14,6 +15,9 @@ using System.Drawing;
 using System.Linq;
 using System.Threading.Tasks;
 using System.Windows.Forms;
+using System.Linq;
+using System.Linq.Expressions;
+using Microsoft.EntityFrameworkCore.Query;
 namespace DW5S.App.UserControl
 {
     public partial class CtrlRefTask : DevExpress.XtraEditors.XtraUserControl
@@ -41,7 +45,7 @@ namespace DW5S.App.UserControl
                             var ids = data.Select(p => p.Id);
                             var unitOfWork = IocContainer.UnitOfWork;
                             var reps = unitOfWork.OfLong<RefTaskFreq>();
-                            await reps.UpdatePropAsync(p => ids.Contains(p.Id), p => p.Enable, true);
+                            await reps.UpdatePropAsync(p => ids.Contains(p.Id), s => s.SetProperty(b => b.Enable, true));
                             await unitOfWork.SaveAsync();
 
                             data.ForEach(d => d.Enable = true);
@@ -54,7 +58,7 @@ namespace DW5S.App.UserControl
                             IocContainer.Logger.Error(ex, "一键启用异常");
                         }
                     }, false)
-                    .AddContentMenu<RefTaskFreq>("一键禁用", SvgHelper.CreateCycle("#FF0000"), async data =>
+                    .AddContentMenu<RefTaskViewModel>("一键禁用", SvgHelper.CreateCycle("#FF0000"), async data =>
                      {
 
                          try
@@ -62,7 +66,7 @@ namespace DW5S.App.UserControl
                              var ids = data.Select(p => p.Id);
                              var unitOfWork = IocContainer.UnitOfWork;
                              var reps = unitOfWork.OfLong<RefTaskFreq>();
-                             await reps.UpdatePropAsync(p => ids.Contains(p.Id), p => p.Enable, false);
+                             await reps.UpdatePropAsync(p => ids.Contains(p.Id), s => s.SetProperty(b => b.Enable, false));
                              await unitOfWork.SaveAsync();
 
                              data.ForEach(d => d.Enable = false);

+ 1 - 0
DW5S.Repostory/04.DW5S.Repostory.csproj

@@ -13,6 +13,7 @@
 			<PrivateAssets>all</PrivateAssets>
 			<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
 		</PackageReference>
+		<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.20" />
 		<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.20">
 			<PrivateAssets>all</PrivateAssets>
 			<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

+ 5 - 7
DW5S.Repostory/Repository/IRepository.cs

@@ -27,14 +27,12 @@ namespace DW5S.Repostory
 
         /// <summary>
         /// 修改某些字段
+        /// expression  s => s.SetProperty(b => b.Enable, true)
         /// </summary>
-        /// <typeparam name="TProperty"></typeparam>
         /// <param name="predicate"></param>
-        /// <param name="propertyExpression"></param>
-        /// <param name="value"></param>
+        /// <param name="expression">ddd</param>
         /// <returns></returns>
-        Task<int> UpdatePropAsync<TProperty>(Expression<Func<T, bool>> predicate, Func<T, TProperty> propertyExpression, TProperty value);
-
+        Task<int> UpdatePropAsync(Expression<Func<T, bool>> predicate, Expression<Func<SetPropertyCalls<T>, SetPropertyCalls<T>>> expression);
 
         Task<int> DeleteAsync(T entity);
         Task<int> DeleteAsync(IEnumerable<T> entitis);
@@ -185,10 +183,10 @@ namespace DW5S.Repostory
         }
 
 
-        public async Task<int> UpdatePropAsync<TProperty>(Expression<Func<T, bool>> predicate, Func<T, TProperty> propertyExpression, TProperty value)
+        public async Task<int> UpdatePropAsync(Expression<Func<T, bool>> predicate, Expression<Func<SetPropertyCalls<T>, SetPropertyCalls<T>>> expression)
         {
             return await dbSet.Where(predicate)
-                .ExecuteUpdateAsync(setters => setters.SetProperty(propertyExpression, value));
+                .ExecuteUpdateAsync(expression);
         }
     }
 }