Browse Source

Add null checks in OnConfiguring of AbpDbContext

pull/24343/head
maliming 11 months ago
parent
commit
6bb63e170a
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 17
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs

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

@ -117,7 +117,12 @@ public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext,
{ {
optionsBuilder.ConfigureWarnings(c => c.Ignore(RelationalEventId.PendingModelChangesWarning)); optionsBuilder.ConfigureWarnings(c => c.Ignore(RelationalEventId.PendingModelChangesWarning));
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
if (LazyServiceProvider == null || Options == null)
{
return;
}
Options.Value.DefaultOnConfiguringAction?.Invoke(this, optionsBuilder); Options.Value.DefaultOnConfiguringAction?.Invoke(this, optionsBuilder);
foreach (var onConfiguringAction in Options.Value.OnConfiguringActions.GetOrDefault(typeof(TDbContext)) ?? []) foreach (var onConfiguringAction in Options.Value.OnConfiguringActions.GetOrDefault(typeof(TDbContext)) ?? [])
{ {
@ -810,7 +815,7 @@ public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext,
modelBuilder, modelBuilder,
mutableEntityType mutableEntityType
); );
entityTypeBuilder.ConfigureByConvention(); entityTypeBuilder.ConfigureByConvention();
ConfigureGlobalFilters<TEntity>(modelBuilder, mutableEntityType, entityTypeBuilder); ConfigureGlobalFilters<TEntity>(modelBuilder, mutableEntityType, entityTypeBuilder);
@ -827,7 +832,7 @@ public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext,
protected virtual void ConfigureGlobalFilters<TEntity>( protected virtual void ConfigureGlobalFilters<TEntity>(
ModelBuilder modelBuilder, ModelBuilder modelBuilder,
IMutableEntityType mutableEntityType, IMutableEntityType mutableEntityType,
EntityTypeBuilder<TEntity> entityTypeBuilder) EntityTypeBuilder<TEntity> entityTypeBuilder)
where TEntity : class where TEntity : class
{ {
@ -858,7 +863,7 @@ public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext,
{ {
return; return;
} }
foreach (var property in mutableEntityType.GetProperties(). foreach (var property in mutableEntityType.GetProperties().
Where(property => property.PropertyInfo != null && Where(property => property.PropertyInfo != null &&
@ -870,7 +875,7 @@ public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext,
modelBuilder, modelBuilder,
mutableEntityType mutableEntityType
); );
entityTypeBuilder entityTypeBuilder
.Property(property.Name) .Property(property.Name)
.HasConversion(property.ClrType == typeof(DateTime) .HasConversion(property.ClrType == typeof(DateTime)
@ -880,7 +885,7 @@ public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext,
} }
protected virtual void ConfigureValueGenerated<TEntity>( protected virtual void ConfigureValueGenerated<TEntity>(
ModelBuilder modelBuilder, ModelBuilder modelBuilder,
IMutableEntityType mutableEntityType) IMutableEntityType mutableEntityType)
where TEntity : class where TEntity : class
{ {

Loading…
Cancel
Save