mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 15:20:48 -05:00
update for database provider specific migrations
fix issues with live radar
This commit is contained in:
@ -1,4 +1,7 @@
|
||||
using SharedLibraryCore.Database;
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SharedLibraryCore.Database;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
|
||||
namespace IW4MAdmin.Application.Factories
|
||||
@ -8,6 +11,13 @@ namespace IW4MAdmin.Application.Factories
|
||||
/// </summary>
|
||||
public class DatabaseContextFactory : IDatabaseContextFactory
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public DatabaseContextFactory(IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// creates a new database context
|
||||
/// </summary>
|
||||
@ -15,7 +25,24 @@ namespace IW4MAdmin.Application.Factories
|
||||
/// <returns></returns>
|
||||
public DatabaseContext CreateContext(bool? enableTracking = true)
|
||||
{
|
||||
return enableTracking.HasValue ? new DatabaseContext(disableTracking: !enableTracking.Value) : new DatabaseContext();
|
||||
var context = _serviceProvider.GetRequiredService<DatabaseContext>();
|
||||
|
||||
enableTracking ??= true;
|
||||
|
||||
if (enableTracking.Value)
|
||||
{
|
||||
context.ChangeTracker.AutoDetectChangesEnabled = true;
|
||||
context.ChangeTracker.LazyLoadingEnabled = true;
|
||||
context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.TrackAll;
|
||||
}
|
||||
else
|
||||
{
|
||||
context.ChangeTracker.AutoDetectChangesEnabled = false;
|
||||
context.ChangeTracker.LazyLoadingEnabled = false;
|
||||
context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user