diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs index e91d08b8c9..797e4dbb67 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs @@ -124,7 +124,7 @@ public abstract class AbpDbContext : DbContext, IAbpEfCoreDbContext, TrySetDatabaseProvider(modelBuilder); - foreach (var entityType in modelBuilder.Model.GetEntityTypes()) + foreach (var entityType in modelBuilder.Model.GetEntityTypes().ToArray()) { ConfigureBasePropertiesMethodInfo .MakeGenericMethod(entityType.ClrType) @@ -796,29 +796,31 @@ public abstract class AbpDbContext : DbContext, IAbpEfCoreDbContext, protected virtual void ConfigureValueConverter(ModelBuilder modelBuilder, IMutableEntityType mutableEntityType) where TEntity : class { - if (mutableEntityType.BaseType == null && - !typeof(TEntity).IsDefined(typeof(DisableDateTimeNormalizationAttribute), true) && - !typeof(TEntity).IsDefined(typeof(OwnedAttribute), true) && - !mutableEntityType.IsOwned()) + if (mutableEntityType.BaseType != null || + typeof(TEntity).IsDefined(typeof(DisableDateTimeNormalizationAttribute), true) || + typeof(TEntity).IsDefined(typeof(OwnedAttribute), true) || + mutableEntityType.IsOwned()) { - if (LazyServiceProvider == null || Clock == null) - { - return; - } + return; + } - foreach (var property in mutableEntityType.GetProperties(). - Where(property => property.PropertyInfo != null && - (property.PropertyInfo.PropertyType == typeof(DateTime) || property.PropertyInfo.PropertyType == typeof(DateTime?)) && - property.PropertyInfo.CanWrite && - ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrDefault(property.PropertyInfo) == null)) - { - modelBuilder - .Entity() - .Property(property.Name) - .HasConversion(property.ClrType == typeof(DateTime) - ? new AbpDateTimeValueConverter(Clock) - : new AbpNullableDateTimeValueConverter(Clock)); - } + if (LazyServiceProvider == null || Clock == null) + { + return; + } + + foreach (var property in mutableEntityType.GetProperties(). + Where(property => property.PropertyInfo != null && + (property.PropertyInfo.PropertyType == typeof(DateTime) || property.PropertyInfo.PropertyType == typeof(DateTime?)) && + property.PropertyInfo.CanWrite && + ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrDefault(property.PropertyInfo) == null)) + { + modelBuilder + .Entity() + .Property(property.Name) + .HasConversion(property.ClrType == typeof(DateTime) + ? new AbpDateTimeValueConverter(Clock) + : new AbpNullableDateTimeValueConverter(Clock)); } }