Browse Source

GetEntityTypes() is called with ToArray()

To prevent "enumaration is modified" problem
pull/23585/head
Halil İbrahim Kalkan 1 year ago
parent
commit
826d67d3ec
  1. 46
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs

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

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

Loading…
Cancel
Save