Browse Source
Merge pull request #4920 from abpframework/maliming/HandleExtraPropertiesOnSave
Convert entity property to entry property type.
pull/5022/head
Halil İbrahim Kalkan
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
42 additions and
6 deletions
-
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs
-
framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Domain/ExtraProperties_Tests.cs
-
framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Domain/TestEntityExtensionConfigurator.cs
-
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs
|
|
|
@ -1,6 +1,7 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.ComponentModel.DataAnnotations.Schema; |
|
|
|
using System.Globalization; |
|
|
|
using System.Linq; |
|
|
|
using System.Linq.Expressions; |
|
|
|
using System.Reflection; |
|
|
|
@ -322,7 +323,25 @@ namespace Volo.Abp.EntityFrameworkCore |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
entry.Property(property.Name).CurrentValue = entity.GetProperty(property.Name); |
|
|
|
var entryProperty = entry.Property(property.Name); |
|
|
|
var entityProperty = entity.GetProperty(property.Name); |
|
|
|
if (entityProperty == null) |
|
|
|
{ |
|
|
|
entryProperty.CurrentValue = null; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
if (entryProperty.Metadata.ClrType == entityProperty.GetType()) |
|
|
|
{ |
|
|
|
entryProperty.CurrentValue = entityProperty; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (TypeHelper.IsPrimitiveExtended(entryProperty.Metadata.ClrType, includeEnums: true)) |
|
|
|
{ |
|
|
|
entryProperty.CurrentValue = Convert.ChangeType(entityProperty, entryProperty.Metadata.ClrType, CultureInfo.InvariantCulture); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -26,11 +26,15 @@ namespace Volo.Abp.EntityFrameworkCore.Domain |
|
|
|
var london = await CityRepository.FindByNameAsync("London"); |
|
|
|
london.GetProperty<string>("PhoneCode").ShouldBe("42"); |
|
|
|
|
|
|
|
london.ExtraProperties["PhoneCode"] = "53"; |
|
|
|
london.ExtraProperties["PhoneCode"] = 123456; |
|
|
|
london.ExtraProperties["Rank"] = "88"; |
|
|
|
london.ExtraProperties["ZipCode"] = null; |
|
|
|
await CityRepository.UpdateAsync(london); |
|
|
|
|
|
|
|
var london2 = await CityRepository.FindByNameAsync("London"); |
|
|
|
london2.GetProperty<string>("PhoneCode").ShouldBe("53"); |
|
|
|
london2.GetProperty<string>("PhoneCode").ShouldBe("123456"); |
|
|
|
london2.GetProperty<int>("Rank").ShouldBe(88); |
|
|
|
london2.GetProperty<string>("ZipCode").ShouldBe(null); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -19,7 +19,12 @@ namespace Volo.Abp.EntityFrameworkCore.Domain |
|
|
|
{ |
|
|
|
e.HasIndex(p.Metadata.Name).IsUnique(); |
|
|
|
p.HasMaxLength(8); |
|
|
|
}); |
|
|
|
} |
|
|
|
).MapEfCoreProperty<City, string>( |
|
|
|
"ZipCode" |
|
|
|
).MapEfCoreProperty<City, int>( |
|
|
|
"Rank" |
|
|
|
); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -46,7 +46,15 @@ namespace Volo.Abp.TestApp |
|
|
|
|
|
|
|
await _cityRepository.InsertAsync(new City(Guid.NewGuid(), "Tokyo")); |
|
|
|
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(new City(Guid.NewGuid(), "Paris")); |
|
|
|
await _cityRepository.InsertAsync(new City(Guid.NewGuid(), "Washington")); |
|
|
|
@ -79,4 +87,4 @@ namespace Volo.Abp.TestApp |
|
|
|
await _entityWithIntPksRepository.InsertAsync(new EntityWithIntPk("Entity1")); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|