|
|
|
@ -37,7 +37,7 @@ namespace Volo.Abp.EntityFrameworkCore; |
|
|
|
public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext, ITransientDependency |
|
|
|
where TDbContext : DbContext |
|
|
|
{ |
|
|
|
public IAbpLazyServiceProvider LazyServiceProvider { get; set; } |
|
|
|
public IAbpLazyServiceProvider LazyServiceProvider { get; set; } = default!; |
|
|
|
|
|
|
|
protected virtual Guid? CurrentTenantId => CurrentTenant?.Id; |
|
|
|
|
|
|
|
@ -74,21 +74,21 @@ public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext, |
|
|
|
.GetMethod( |
|
|
|
nameof(ConfigureBaseProperties), |
|
|
|
BindingFlags.Instance | BindingFlags.NonPublic |
|
|
|
); |
|
|
|
)!; |
|
|
|
|
|
|
|
private static readonly MethodInfo ConfigureValueConverterMethodInfo |
|
|
|
= typeof(AbpDbContext<TDbContext>) |
|
|
|
.GetMethod( |
|
|
|
nameof(ConfigureValueConverter), |
|
|
|
BindingFlags.Instance | BindingFlags.NonPublic |
|
|
|
); |
|
|
|
)!; |
|
|
|
|
|
|
|
private static readonly MethodInfo ConfigureValueGeneratedMethodInfo |
|
|
|
= typeof(AbpDbContext<TDbContext>) |
|
|
|
.GetMethod( |
|
|
|
nameof(ConfigureValueGenerated), |
|
|
|
BindingFlags.Instance | BindingFlags.NonPublic |
|
|
|
); |
|
|
|
)!; |
|
|
|
|
|
|
|
protected AbpDbContext(DbContextOptions<TDbContext> options) |
|
|
|
: base(options) |
|
|
|
@ -157,7 +157,7 @@ public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext, |
|
|
|
try |
|
|
|
{ |
|
|
|
var auditLog = AuditingManager?.Current?.Log; |
|
|
|
List<EntityChangeInfo> entityChangeList = null; |
|
|
|
List<EntityChangeInfo>? entityChangeList = null; |
|
|
|
if (auditLog != null) |
|
|
|
{ |
|
|
|
entityChangeList = EntityHistoryHelper.CreateChangeList(ChangeTracker.Entries().ToList()); |
|
|
|
@ -174,7 +174,7 @@ public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext, |
|
|
|
if (entityChangeList != null) |
|
|
|
{ |
|
|
|
EntityHistoryHelper.UpdateChangeList(entityChangeList); |
|
|
|
auditLog.EntityChanges.AddRange(entityChangeList); |
|
|
|
auditLog!.EntityChanges.AddRange(entityChangeList); |
|
|
|
Logger.LogDebug($"Added {entityChangeList.Count} entity changes to the current audit log"); |
|
|
|
} |
|
|
|
|
|
|
|
@ -249,13 +249,13 @@ public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual void ChangeTracker_Tracked(object sender, EntityTrackedEventArgs e) |
|
|
|
protected virtual void ChangeTracker_Tracked(object? sender, EntityTrackedEventArgs e) |
|
|
|
{ |
|
|
|
FillExtraPropertiesForTrackedEntities(e); |
|
|
|
PublishEventsForTrackedEntity(e.Entry); |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual void ChangeTracker_StateChanged(object sender, EntityStateChangedEventArgs e) |
|
|
|
protected virtual void ChangeTracker_StateChanged(object? sender, EntityStateChangedEventArgs e) |
|
|
|
{ |
|
|
|
PublishEventsForTrackedEntity(e.Entry); |
|
|
|
} |
|
|
|
@ -453,11 +453,11 @@ public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext, |
|
|
|
|
|
|
|
if (conversionType == typeof(Guid)) |
|
|
|
{ |
|
|
|
entryProperty.CurrentValue = TypeDescriptor.GetConverter(conversionType).ConvertFromInvariantString(entityProperty.ToString()); |
|
|
|
entryProperty.CurrentValue = TypeDescriptor.GetConverter(conversionType).ConvertFromInvariantString(entityProperty.ToString()!); |
|
|
|
} |
|
|
|
else if (conversionType.IsEnum) |
|
|
|
{ |
|
|
|
entryProperty.CurrentValue = Enum.Parse(conversionType, entityProperty.ToString(), ignoreCase: true); |
|
|
|
entryProperty.CurrentValue = Enum.Parse(conversionType, entityProperty.ToString()!, ignoreCase: true); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
@ -560,7 +560,7 @@ public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext, |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
var idProperty = entry.Property("Id").Metadata.PropertyInfo; |
|
|
|
var idProperty = entry.Property("Id").Metadata.PropertyInfo!; |
|
|
|
|
|
|
|
//Check for DatabaseGeneratedAttribute
|
|
|
|
var dbGeneratedAttr = ReflectionHelper |
|
|
|
@ -669,7 +669,7 @@ public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext, |
|
|
|
} |
|
|
|
|
|
|
|
var idPropertyBuilder = modelBuilder.Entity<TEntity>().Property(x => ((IEntity<Guid>)x).Id); |
|
|
|
if (idPropertyBuilder.Metadata.PropertyInfo.IsDefined(typeof(DatabaseGeneratedAttribute), true)) |
|
|
|
if (idPropertyBuilder.Metadata.PropertyInfo!.IsDefined(typeof(DatabaseGeneratedAttribute), true)) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
@ -692,10 +692,10 @@ public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext, |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual Expression<Func<TEntity, bool>> CreateFilterExpression<TEntity>() |
|
|
|
protected virtual Expression<Func<TEntity, bool>>? CreateFilterExpression<TEntity>() |
|
|
|
where TEntity : class |
|
|
|
{ |
|
|
|
Expression<Func<TEntity, bool>> expression = null; |
|
|
|
Expression<Func<TEntity, bool>>? expression = null; |
|
|
|
|
|
|
|
if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity))) |
|
|
|
{ |
|
|
|
|