Browse Source

Allow to set the value of ExtraProperties to null.

pull/4920/head
maliming 6 years ago
parent
commit
40ceea0356
  1. 4
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs
  2. 2
      framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Domain/ExtraProperties_Tests.cs
  3. 2
      framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Domain/TestEntityExtensionConfigurator.cs
  4. 12
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs

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

@ -315,14 +315,14 @@ namespace Volo.Abp.EntityFrameworkCore
continue; continue;
} }
var entryProperty = entry.Property(property.Name);
var entityProperty = entity.GetProperty(property.Name); var entityProperty = entity.GetProperty(property.Name);
if (entityProperty == null) if (entityProperty == null)
{ {
entryProperty.CurrentValue = null;
continue; continue;
} }
var entryProperty = entry.Property(property.Name);
if (entryProperty.Metadata.ClrType == entityProperty.GetType()) if (entryProperty.Metadata.ClrType == entityProperty.GetType())
{ {
entryProperty.CurrentValue = entityProperty; entryProperty.CurrentValue = entityProperty;

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

@ -24,11 +24,13 @@ namespace Volo.Abp.EntityFrameworkCore.Domain
london.ExtraProperties["PhoneCode"] = 123456; london.ExtraProperties["PhoneCode"] = 123456;
london.ExtraProperties["Rank"] = "88"; london.ExtraProperties["Rank"] = "88";
london.ExtraProperties["ZipCode"] = null;
await CityRepository.UpdateAsync(london); await CityRepository.UpdateAsync(london);
var london2 = await CityRepository.FindByNameAsync("London"); var london2 = await CityRepository.FindByNameAsync("London");
london2.GetProperty<string>("PhoneCode").ShouldBe("123456"); london2.GetProperty<string>("PhoneCode").ShouldBe("123456");
london2.GetProperty<int>("Rank").ShouldBe(88); london2.GetProperty<int>("Rank").ShouldBe(88);
london2.GetProperty<string>("ZipCode").ShouldBe(null);
} }
} }
} }

2
framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Domain/TestEntityExtensionConfigurator.cs

@ -16,6 +16,8 @@ namespace Volo.Abp.EntityFrameworkCore.Domain
.MapEfCoreProperty<City, string>( .MapEfCoreProperty<City, string>(
"PhoneCode", "PhoneCode",
p => p.HasMaxLength(8) p => p.HasMaxLength(8)
).MapEfCoreProperty<City, string>(
"ZipCode"
).MapEfCoreProperty<City, int>( ).MapEfCoreProperty<City, int>(
"Rank" "Rank"
); );

12
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs

@ -46,7 +46,15 @@ namespace Volo.Abp.TestApp
await _cityRepository.InsertAsync(new City(Guid.NewGuid(), "Tokyo")); await _cityRepository.InsertAsync(new City(Guid.NewGuid(), "Tokyo"));
await _cityRepository.InsertAsync(new City(Guid.NewGuid(), "Madrid")); await _cityRepository.InsertAsync(new City(Guid.NewGuid(), "Madrid"));
await _cityRepository.InsertAsync(new City(LondonCityId, "London") { ExtraProperties = { { "Population", 10_470_000 }, { "PhoneCode", "42" } } }); await _cityRepository.InsertAsync(new City(LondonCityId, "London")
{
ExtraProperties =
{
{ "Population", 10_470_000 },
{ "PhoneCode", "42" },
{ "ZipCode", "1000" }
}
});
await _cityRepository.InsertAsync(istanbul); await _cityRepository.InsertAsync(istanbul);
await _cityRepository.InsertAsync(new City(Guid.NewGuid(), "Paris")); await _cityRepository.InsertAsync(new City(Guid.NewGuid(), "Paris"));
await _cityRepository.InsertAsync(new City(Guid.NewGuid(), "Washington")); await _cityRepository.InsertAsync(new City(Guid.NewGuid(), "Washington"));
@ -79,4 +87,4 @@ namespace Volo.Abp.TestApp
await _entityWithIntPksRepository.InsertAsync(new EntityWithIntPk("Entity1")); await _entityWithIntPksRepository.InsertAsync(new EntityWithIntPk("Entity1"));
} }
} }
} }

Loading…
Cancel
Save