首页 > 解决方案 > GetListAsync 正在返回记录,包括 IsDeleted 为 true

问题描述

我有一个继承 ISoftDelete 的实体模型。当我使用 DeleteAsync 删除记录时,ABP 将 IsDeleted 成功设置为 true。

但是使用 GetListAsync 时会返回软删除的记录。

使用 ABP 2.8。

using Volo.Abp;
using Volo.Abp.Domain.Entities;

namespace POC.DataModels
{
    public partial class Employee : Entity<int>, ISoftDelete
    {
        protected Employee()
        {

        }

        public Employee(int id)
         : base(id)
        {

        }
        public string Name { get; set; }
        public bool IsDeleted { get; set; }
    }
}

using System.Collections.Generic;
using System.Threading.Tasks;
using POC.DataModels;
using Volo.Abp.Domain.Repositories;

namespace POC
{
    public class EmployeeService : PocAppService
    {
        private readonly IRepository<Employee> _employeeRepository;

        public EmployeeService(IRepository<Employee> employeeRepository)
        {
            _employeeRepository = employeeRepository;
        }

        public async Task<IReadOnlyList<Employee>> GetAllEmployeesAsync()
        {
            return await _employeeRepository.GetListAsync().ConfigureAwait(false);
        }

        public async Task DeleteEmployeeAsync(int employeeId)
        {
            await _employeeRepository.DeleteAsync(x=>x.Id == employeeId).ConfigureAwait(false);
        }
    }
}

标签: abp

解决方案


推荐阅读