RepositoryExtension.cs 881 B

12345678910111213141516171819202122
  1. using SqlSugar;
  2. namespace Admin.NET.Core.Extension
  3. {
  4. public static class RepositoryExtension
  5. {
  6. /// <summary>
  7. /// 实体假删除 _rep.Context.Updateable(entity).FakeDelete().ExecuteCommandAsync();
  8. /// </summary>
  9. /// <typeparam name="T"></typeparam>
  10. /// <param name="updateable"></param>
  11. /// <returns></returns>
  12. public static IUpdateable<T> FakeDelete<T>(this IUpdateable<T> updateable) where T : EntityBase, new()
  13. {
  14. return updateable.ReSetValue(x => { x.IsDelete = true; })
  15. .IgnoreColumns(ignoreAllNullColumns: true)
  16. .EnableDiffLogEvent() // 记录差异日志
  17. .UpdateColumns(x => new { x.IsDelete, x.UpdateTime, x.UpdateUserId }); // 允许更新的字段-AOP拦截自动设置UpdateTime、UpdateUserId
  18. }
  19. }
  20. }