diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EfCoreRepositoryExtensions.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EfCoreRepositoryExtensions.cs index e7f14c51d8..646259f941 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EfCoreRepositoryExtensions.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EfCoreRepositoryExtensions.cs @@ -11,17 +11,17 @@ namespace Volo.Abp.Repositories public static DbContext GetDbContext(this IRepository repository) where TEntity : class, IEntity, new() { - var efCoreRepository = repository as IEfCoreRepository; - if (efCoreRepository == null) - { - throw new ArgumentException("Given repository does not implement " + typeof(IEfCoreRepository).AssemblyQualifiedName, nameof(repository)); - } - - return efCoreRepository.DbContext; + return repository.ToEfCoreRepository().DbContext; } public static DbSet GetDbSet(this IRepository repository) where TEntity : class, IEntity, new() + { + return repository.ToEfCoreRepository().DbSet; + } + + public static IEfCoreRepository ToEfCoreRepository(this IRepository repository) + where TEntity : class, IEntity, new() { var efCoreRepository = repository as IEfCoreRepository; if (efCoreRepository == null) @@ -29,7 +29,7 @@ namespace Volo.Abp.Repositories throw new ArgumentException("Given repository does not implement " + typeof(IEfCoreRepository).AssemblyQualifiedName, nameof(repository)); } - return efCoreRepository.DbSet; + return efCoreRepository; } } } diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/EfCoreRepository.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/EfCoreRepository.cs index 8958580e9f..f7754fd058 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/EfCoreRepository.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/EfCoreRepository.cs @@ -12,11 +12,11 @@ namespace Volo.Abp.Repositories.EntityFrameworkCore where TDbContext : AbpDbContext where TEntity : class, IEntity { - public virtual TDbContext DbContext => _dbContextProvider.GetDbContext(); - public virtual DbSet DbSet => DbContext.Set(); - DbContext IEfCoreRepository.DbContext => DbContext; + DbContext IEfCoreRepository.DbContext => DbContext; + + protected virtual TDbContext DbContext => _dbContextProvider.GetDbContext(); private readonly IDbContextProvider _dbContextProvider; diff --git a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/IEfCoreRepository.cs b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/IEfCoreRepository.cs index 684512d1d0..3f2d08f9f6 100644 --- a/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/IEfCoreRepository.cs +++ b/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Repositories/EntityFrameworkCore/IEfCoreRepository.cs @@ -1,16 +1,14 @@ using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Entities; +using Volo.Abp.Domain.Repositories; namespace Volo.Abp.Repositories.EntityFrameworkCore { - public interface IEfCoreRepository - { - DbContext DbContext { get; } - } - - public interface IEfCoreRepository : IEfCoreRepository + public interface IEfCoreRepository : IQueryableRepository where TEntity : class, IEntity { + DbContext DbContext { get; } + DbSet DbSet { get; } } } \ No newline at end of file diff --git a/src/Volo.DependencyInjection/Volo/DependencyInjection/ExposeServicesAttribute.cs b/src/Volo.DependencyInjection/Volo/DependencyInjection/ExposeServicesAttribute.cs index 72c05fdc2a..31e898ce2c 100644 --- a/src/Volo.DependencyInjection/Volo/DependencyInjection/ExposeServicesAttribute.cs +++ b/src/Volo.DependencyInjection/Volo/DependencyInjection/ExposeServicesAttribute.cs @@ -8,7 +8,7 @@ namespace Volo.DependencyInjection public ExposeServicesAttribute(params Type[] exposedServiceTypes) { - ExposedServiceTypes = exposedServiceTypes ?? new Type[]; + ExposedServiceTypes = exposedServiceTypes ?? new Type[0]; } public Type[] GetExposedServiceTypes()