From f815aba4b877ef2085dc465319552241ce43c922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 30 Mar 2023 15:20:32 +0300 Subject: [PATCH] Add GetDbConnectionAsync and GetDbTransactionAsync methods to EF Core base repository class --- .../EntityFrameworkCore/EfCoreRepository.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs index e9e1f2c618..96d7b4111e 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs @@ -4,11 +4,13 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using System; using System.Collections.Generic; +using System.Data; using System.Linq; using System.Linq.Dynamic.Core; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore.Storage; using Volo.Abp.Domain.Entities; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.DependencyInjection; @@ -73,6 +75,16 @@ public class EfCoreRepository : RepositoryBase, IE { return (await GetDbContextAsync()).Set(); } + + protected async Task GetDbConnectionAsync() + { + return (await GetDbContextAsync()).Database.GetDbConnection(); + } + + protected async Task GetDbTransactionAsync() + { + return (await GetDbContextAsync()).Database.CurrentTransaction?.GetDbTransaction(); + } protected virtual AbpEntityOptions AbpEntityOptions => _entityOptionsLazy.Value;