Hi,
Based on the documentation on this link when you use a repository: "You can also use the Context object in the repository methods to reach your DbContext and directly use Entity Framework APIs"
However I dont see how is this possible as no Context property exists on my IRepository<T, int>
Any tips?
Thanks in advance
3 Answer(s)
-
0
Hi @antonis
It is valid for custom repositories. So, if you crete a custom repository inheriting from *RepositoryBase class, then you can access dbContext inside from repository method. Maybe it is not expressed clearly here.
If you are using a generic repository and want to access DbContext in an app service or controller, you can inject IDbContextProvider<TDbContext> and use it to access the DbContext.
-
1
// using Abp.EntityFrameworkCore.Repositories; var context = _repository.GetDbContext();
-
0
@ismcagdas once i want to inject IDbContextProvider to AppService`s ctor, get an exception 'could not proxy xxxxAppService'. where and how to get DbContext?