Browse Source

Backup `ExtraProperties` during `Reload` entry.

Because `Reload` will not convert the `ExtraProperties` from the JSON string to the `Dictionary`.
pull/20750/head
maliming 1 year ago
parent
commit
078643680c
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 12
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs
  2. 22
      framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Domain/ExtraProperties_Tests.cs
  3. 4
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/City.cs
  4. 3
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/ConcurrencyStamp_Tests.cs

12
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs

@ -614,7 +614,19 @@ public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext,
return;
}
ExtraPropertyDictionary? originalExtraProperties = null;
if (entry.Entity is IHasExtraProperties)
{
originalExtraProperties = entry.OriginalValues.GetValue<ExtraPropertyDictionary>(nameof(IHasExtraProperties.ExtraProperties));
}
entry.Reload();
if (entry.Entity is IHasExtraProperties)
{
ObjectHelper.TrySetProperty(entry.Entity.As<IHasExtraProperties>(), x => x.ExtraProperties, () => originalExtraProperties);
}
ObjectHelper.TrySetProperty(entry.Entity.As<ISoftDelete>(), x => x.IsDeleted, () => true);
SetDeletionAuditProperties(entry);
}

22
framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Domain/ExtraProperties_Tests.cs

@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.Data;
using Volo.Abp.Domain.Repositories;
@ -59,6 +60,27 @@ public class ExtraProperties_Tests : ExtraProperties_Tests<AbpEntityFrameworkCor
});
}
[Fact]
public async Task Should_Get_An_Extra_Property_After_Soft_Deletion()
{
var london = await CityRepository.FindByNameAsync("London");
london.HasProperty("PhoneCode").ShouldBeTrue();
london.GetProperty<string>("PhoneCode").ShouldBe("42");
await CityRepository.DeleteAsync(london);
london = await CityRepository.FindByNameAsync("London");
london.ShouldBeNull();
using (var uow = ServiceProvider.GetRequiredService<IDataFilter>().Disable<ISoftDelete>())
{
london = await CityRepository.FindByNameAsync("London");
london.IsDeleted.ShouldBeTrue();
london.HasProperty("PhoneCode").ShouldBeTrue();
london.GetProperty<string>("PhoneCode").ShouldBe("42");
}
}
public enum Color
{
Red = 0,

4
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/City.cs

@ -5,12 +5,14 @@ using Volo.Abp.Domain.Entities;
namespace Volo.Abp.TestApp.Domain;
public class City : AggregateRoot<Guid>
public class City : AggregateRoot<Guid>, ISoftDelete
{
public string Name { get; set; }
public ICollection<District> Districts { get; set; }
public bool IsDeleted { get; set; }
private City()
{

3
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/ConcurrencyStamp_Tests.cs

@ -1,5 +1,6 @@
using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Modularity;
using Volo.Abp.TestApp.Domain;
using Xunit;
@ -49,7 +50,7 @@ public abstract class ConcurrencyStamp_Tests<TStartupModule> : TestAppTestBase<T
//And deleting my old entity throws exception!
await Assert.ThrowsAsync<AbpDbConcurrencyException>(async () =>
{
await CityRepository.DeleteAsync(london1);
await CityRepository.HardDeleteAsync(london1);
});
}
}

Loading…
Cancel
Save