abpframework / abp

Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
https://abp.io
GNU Lesser General Public License v3.0
12.85k stars 3.43k forks source link

Get datas of soft deleted! #9604

Closed weiwxg closed 3 years ago

weiwxg commented 3 years ago

I have a entity which not set DbSet<?> Property in DbContext. Then when i use Repository.GetAsync(id), i get the deleted item!

public class Foo : FullAuditedAggregateRoot<Guid>
{
    // ...
}

public class BasicSettingDbContext : AbpDbContext<BasicSettingDbContext>
{
    // without this line.
    public DbSet<Foo> Fooes { get; set; }
}
maliming commented 3 years ago
weiwxg commented 3 years ago
maliming commented 3 years ago

Full steps are needed to reproduce the problem.

weiwxg commented 3 years ago
// entity
public class Foo : FullAuditedAggregateRoot<Guid>
{

}
// dbcontext
public class BasicSettingDbContext : AbpDbContext<BasicSettingDbContext>
{
    // without this line.
    // public DbSet<Foo> Fooes { get; set; }

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);

        builder.Entity<Foo>(b =>
        {
            b.ToTable(BasicSettingConsts.DbTablePrefix + "Fooes", BasicSettingConsts.DbSchema);
            b.ConfigureByConvention();

        });
    }
}

// appservice
public class FooAppService : IFooAppService
{
    public async Task DeleteAsync(Guid id)
    {
        return repository.DeleteAsync(id);
    }

    public async Task<FooDto> GetAsync(Guid id)
    {
        return ObjectMapper.Map<Foo, FooDto>(await repository.GetAsync(id));
    }
}

Firstly, i call HttpGet localhost:5201/api/foos, return 1 items:

{
   "id": "39fdbee9-14b5-365b-69a0-360cf23ba326",
   "isDeleted": 0,
   "DeleterId": null,
   "DeletionTime": null
}

Then, i call HttpDelete localhost:5201/api/foos/39fdbee9-14b5-365b-69a0-360cf23ba326, return 204.

Obviously, the data is deleted.

However, when I call the HttpGet localhost:5201/api/foos again, I can find the deleted data

{
   "id": "39fdbee9-14b5-365b-69a0-360cf23ba326",
   "isDeleted": 1,
   "DeleterId": "39fd76e0-8e06-6ced-8a88-8f605975b625",
   "DeletionTime": "2021-07-16 11:44:40.000"
}
maliming commented 3 years ago

Abp will get EntityTypes by DbSet<>, so you have to add it to AbpDbContextAbpDbContext

https://github.com/abpframework/abp/blob/63417727af1322f5e4e3756fd004b11225ca5f34/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/DbContextHelper.cs#L13