|
|
|
@ -13,6 +13,7 @@ using Volo.Abp.Domain.Entities; |
|
|
|
using Volo.Abp.EntityFrameworkCore; |
|
|
|
using Volo.Abp.EntityFrameworkCore.DependencyInjection; |
|
|
|
using Volo.Abp.Guids; |
|
|
|
using Volo.Abp.MultiTenancy; |
|
|
|
|
|
|
|
namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore |
|
|
|
{ |
|
|
|
@ -21,18 +22,42 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore |
|
|
|
where TEntity : class, IEntity |
|
|
|
{ |
|
|
|
[Obsolete("Use GetDbContextAsync() method.")] |
|
|
|
protected virtual TDbContext DbContext => _dbContextProvider.GetDbContext(); |
|
|
|
protected virtual TDbContext DbContext => GetDbContext(); |
|
|
|
|
|
|
|
[Obsolete("Use GetDbContextAsync() method.")] |
|
|
|
DbContext IEfCoreRepository<TEntity>.DbContext => DbContext.As<DbContext>(); |
|
|
|
DbContext IEfCoreRepository<TEntity>.DbContext => GetDbContext() as DbContext; |
|
|
|
|
|
|
|
async Task<DbContext> IEfCoreRepository<TEntity>.GetDbContextAsync() |
|
|
|
{ |
|
|
|
return await GetDbContextAsync() as DbContext; |
|
|
|
} |
|
|
|
|
|
|
|
[Obsolete("Use GetDbContextAsync() method.")] |
|
|
|
private TDbContext GetDbContext() |
|
|
|
{ |
|
|
|
// Multi-tenancy unaware entities should always use the host connection string
|
|
|
|
if (!EntityHelper.IsMultiTenant<TEntity>()) |
|
|
|
{ |
|
|
|
using (CurrentTenant.Change(null)) |
|
|
|
{ |
|
|
|
return _dbContextProvider.GetDbContext(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return _dbContextProvider.GetDbContext(); |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual Task<TDbContext> GetDbContextAsync() |
|
|
|
{ |
|
|
|
// Multi-tenancy unaware entities should always use the host connection string
|
|
|
|
if (!EntityHelper.IsMultiTenant<TEntity>()) |
|
|
|
{ |
|
|
|
using (CurrentTenant.Change(null)) |
|
|
|
{ |
|
|
|
return _dbContextProvider.GetDbContextAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return _dbContextProvider.GetDbContextAsync(); |
|
|
|
} |
|
|
|
|
|
|
|
|