mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-17 05:54:26 +01:00
22 lines
759 B
C#
22 lines
759 B
C#
#nullable enable
|
|
using System;
|
|
using System.Data.Common;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
|
|
namespace BTCPayServer.Data;
|
|
|
|
public static partial class ApplicationDbContextExtensions
|
|
{
|
|
public static DbContext GetDbContext<T>(this DbSet<T> dbSet) where T : class
|
|
{
|
|
var infrastructure = dbSet as IInfrastructure<IServiceProvider>;
|
|
var serviceProvider = infrastructure.Instance;
|
|
var currentDbContext = (ICurrentDbContext)serviceProvider.GetService(typeof(ICurrentDbContext))!;
|
|
return currentDbContext.Context;
|
|
}
|
|
|
|
public static DbConnection GetDbConnection<T>(this DbSet<T> dbSet) where T : class
|
|
=> dbSet.GetDbContext().Database.GetDbConnection();
|
|
}
|