Browse Source
Merge pull request #2971 from abpframework/maliming/CascadeTiming
Cascading entities should not be deleted when soft deleting entities.
pull/3173/head
Halil İbrahim Kalkan
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
25 additions and
0 deletions
-
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Uow/EntityFrameworkCore/UnitOfWorkDbContextProvider.cs
-
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/SoftDelete_Tests.cs
|
|
|
@ -1,5 +1,6 @@ |
|
|
|
using System; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Microsoft.EntityFrameworkCore.ChangeTracking; |
|
|
|
using Microsoft.EntityFrameworkCore.Storage; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Volo.Abp.Data; |
|
|
|
@ -60,6 +61,8 @@ namespace Volo.Abp.Uow.EntityFrameworkCore |
|
|
|
dbContext.Database.SetCommandTimeout(unitOfWork.Options.Timeout.Value.TotalSeconds.To<int>()); |
|
|
|
} |
|
|
|
|
|
|
|
dbContext.ChangeTracker.CascadeDeleteTiming = CascadeTiming.OnSaveChanges; |
|
|
|
dbContext.ChangeTracker.DeleteOrphansTiming = CascadeTiming.OnSaveChanges; |
|
|
|
return dbContext; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -60,5 +60,27 @@ namespace Volo.Abp.TestApp.Testing |
|
|
|
douglas.Age.ShouldBe(42); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Cascading_Entities_Should_Not_Be_Deleted_When_Soft_Deleting_Entities() |
|
|
|
{ |
|
|
|
var douglas = await PersonRepository.GetAsync(TestDataBuilder.UserDouglasId); |
|
|
|
douglas.Phones.ShouldNotBeEmpty(); |
|
|
|
|
|
|
|
await PersonRepository.DeleteAsync(douglas); |
|
|
|
|
|
|
|
douglas = await PersonRepository.FindAsync(TestDataBuilder.UserDouglasId); |
|
|
|
douglas.ShouldBeNull(); |
|
|
|
|
|
|
|
using (DataFilter.Disable<ISoftDelete>()) |
|
|
|
{ |
|
|
|
douglas = await PersonRepository.FindAsync(TestDataBuilder.UserDouglasId); |
|
|
|
douglas.ShouldNotBeNull(); |
|
|
|
douglas.IsDeleted.ShouldBeTrue(); |
|
|
|
douglas.DeletionTime.ShouldNotBeNull(); |
|
|
|
|
|
|
|
douglas.Phones.ShouldNotBeEmpty(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|