private static bool HasPendingTransaction(this DatabaseFacade database, out Transaction?activeTransaction) { IDatabaseFacadeDependenciesAccessor dependenciesAccessor = database; var transactionManager = dependenciesAccessor.Dependencies.TransactionManager as IExtendedDbContextTransactionManager; Debug.Assert(transactionManager != null, $"{nameof(IDbContextTransactionManager)} of provider {database.ProviderName} does not implement {typeof(IExtendedDbContextTransactionManager)}."); if (database.CurrentTransaction != null) { activeTransaction = null; return(true); } if (transactionManager.SupportsAmbientTransactions) { activeTransaction = (transactionManager is ITransactionEnlistmentManager ? database.GetEnlistedTransaction() : null) ?? Transaction.Current; if (activeTransaction != null && activeTransaction.TransactionInformation.Status == TransactionStatus.Active) { return(true); } } activeTransaction = null; return(false); }
private static IRelationalDatabaseFacadeDependencies GetFacadeDependencies(this IDatabaseFacadeDependenciesAccessor databaseDependenciesAccessor) { IDatabaseFacadeDependencies dependencies = databaseDependenciesAccessor.Dependencies; if (dependencies is IRelationalDatabaseFacadeDependencies relationalDependencies) { return(relationalDependencies); } throw new InvalidOperationException(RelationalStrings.RelationalNotInUse); }