Browse Source
Refine Sqlite interceptor registration logic
pull/24448/head
maliming
10 months ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
2 changed files with
8 additions and
9 deletions
-
framework/src/Volo.Abp.EntityFrameworkCore.Sqlite/Volo/Abp/EntityFrameworkCore/Interceptors/SqliteBusyTimeoutSaveChangesInterceptor.cs
-
framework/src/Volo.Abp.EntityFrameworkCore.Sqlite/Volo/Abp/EntityFrameworkCore/Sqlite/AbpEntityFrameworkCoreSqliteModule.cs
|
|
|
@ -19,7 +19,7 @@ public class SqliteBusyTimeoutSaveChangesInterceptor : SaveChangesInterceptor |
|
|
|
|
|
|
|
public override InterceptionResult<int> SavingChanges(DbContextEventData eventData, InterceptionResult<int> result) |
|
|
|
{ |
|
|
|
if (eventData.Context != null && IsSqlite(eventData.Context)) |
|
|
|
if (eventData.Context != null) |
|
|
|
{ |
|
|
|
eventData.Context.Database.ExecuteSqlRaw(_pragmaCommand); |
|
|
|
} |
|
|
|
@ -29,17 +29,11 @@ public class SqliteBusyTimeoutSaveChangesInterceptor : SaveChangesInterceptor |
|
|
|
|
|
|
|
public override async ValueTask<InterceptionResult<int>> SavingChangesAsync(DbContextEventData eventData, InterceptionResult<int> result, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
if (eventData.Context != null && IsSqlite(eventData.Context)) |
|
|
|
if (eventData.Context != null) |
|
|
|
{ |
|
|
|
await eventData.Context.Database.ExecuteSqlRawAsync(_pragmaCommand, cancellationToken: cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
return await base.SavingChangesAsync(eventData, result, cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private bool IsSqlite(DbContext context) |
|
|
|
{ |
|
|
|
return context.Database.ProviderName != null && context.Database.ProviderName.Contains("Sqlite"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -1,3 +1,5 @@ |
|
|
|
using System.Linq; |
|
|
|
using Microsoft.EntityFrameworkCore.Sqlite.Infrastructure.Internal; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Volo.Abp.EntityFrameworkCore.GlobalFilters; |
|
|
|
using Volo.Abp.EntityFrameworkCore.Interceptors; |
|
|
|
@ -32,7 +34,10 @@ public class AbpEntityFrameworkCoreSqliteModule : AbpModule |
|
|
|
{ |
|
|
|
options.ConfigureDefaultOnConfiguring((dbContext, dbContextOptionsBuilder) => |
|
|
|
{ |
|
|
|
dbContextOptionsBuilder.AddInterceptors(new SqliteBusyTimeoutSaveChangesInterceptor(sqliteOptions.BusyTimeout.Value)); |
|
|
|
if (dbContextOptionsBuilder.Options.Extensions.Any(extension => extension is SqliteOptionsExtension)) |
|
|
|
{ |
|
|
|
dbContextOptionsBuilder.AddInterceptors(new SqliteBusyTimeoutSaveChangesInterceptor(sqliteOptions.BusyTimeout.Value)); |
|
|
|
} |
|
|
|
}, overrideExisting: false); |
|
|
|
}); |
|
|
|
} |
|
|
|
|