diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/Modeling/AbpEntityTypeBuilderExtensions.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/Modeling/AbpEntityTypeBuilderExtensions.cs index 5d002e87fa..cfaee16e6a 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/Modeling/AbpEntityTypeBuilderExtensions.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/Modeling/AbpEntityTypeBuilderExtensions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Volo.Abp.Auditing; using Volo.Abp.Data; using Volo.Abp.Domain.Entities; @@ -60,9 +61,11 @@ public static class AbpEntityTypeBuilderExtensions return; } + var type = typeof(ExtraPropertiesValueConverter<>).MakeGenericType(b.Metadata.ClrType); + var extraPropertiesValueConverter = Activator.CreateInstance(type)!.As>(); b.Property(nameof(IHasExtraProperties.ExtraProperties)) .HasColumnName(nameof(IHasExtraProperties.ExtraProperties)) - .HasConversion(new ExtraPropertiesValueConverter(b.Metadata.ClrType)) + .HasConversion(extraPropertiesValueConverter) .Metadata.SetValueComparer(new ExtraPropertyDictionaryValueComparer()); b.TryConfigureObjectExtensions(); diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/ValueConverters/ExtraPropertiesValueConverter.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/ValueConverters/ExtraPropertiesValueConverter.cs index 980d926c3b..a24284356c 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/ValueConverters/ExtraPropertiesValueConverter.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/ValueConverters/ExtraPropertiesValueConverter.cs @@ -8,22 +8,23 @@ using Volo.Abp.ObjectExtending; namespace Volo.Abp.EntityFrameworkCore.ValueConverters; -public class ExtraPropertiesValueConverter : ValueConverter +public class ExtraPropertiesValueConverter : ValueConverter { - public ExtraPropertiesValueConverter(Type entityType) + public ExtraPropertiesValueConverter() : base( - d => SerializeObject(d, entityType), - s => DeserializeObject(s, entityType)) + d => SerializeObject(d), + s => DeserializeObject(s)) { } public readonly static JsonSerializerOptions SerializeOptions = new JsonSerializerOptions(); - private static string SerializeObject(ExtraPropertyDictionary extraProperties, Type? entityType) + private static string SerializeObject(ExtraPropertyDictionary extraProperties) { var copyDictionary = new Dictionary(extraProperties); + var entityType = typeof(TEntityType); if (entityType != null) { var objectExtension = ObjectExtensionManager.Instance.GetOrNull(entityType); @@ -50,7 +51,7 @@ public class ExtraPropertiesValueConverter : ValueConverter(extraPropertiesAsJson, DeserializeOptions) ?? new ExtraPropertyDictionary(); + var entityType = typeof(TEntityType); if (entityType != null) { var objectExtension = ObjectExtensionManager.Instance.GetOrNull(entityType);