Hello;
I have two projects: ModuleA and DemoCenterApp. DemoCenterApp can use ModuleA.
ModuleA contains an entity named Iletisim. DemoCenterApp contains an entity named Musteri.
The databases of both projects are different.
In DemoCenterAppDbContext, I used [ReplaceDbContext(typeof(IModuleADbContext))] and added:
public DbSet<Iletisim> Iletisims { get; set; }
My problem is that I want to perform a single LINQ query in EfCoreMusteriRepository that includes Iletisim.
However, I am getting the following error:
Cannot use multiple context instances within a single query execution. Ensure the query uses a single context instance. System.InvalidOperationException: Cannot use multiple context instances within a single query execution. Ensure the query uses a single context instance.
I followed the method described in this YouTube video. As mentioned there, isn't using ReplaceDbContext sufficient?
- ABP Framework version: v8.2.2
- UI Type: Angular / MVC
- Database System: EF Core (Oracle)
- Tiered (for MVC) or Auth Server Separated (for Angular): yes
9 Answer(s)
-
0
hi
The databases of both projects are different.
What does that mean?
ModuleA is a module, why is has use a database?
-
0
https://blog.antosubash.com/posts/abp-add-new-module-with-seperate-db
Our requirement is this: we have a large project with separate CRM and ERP modules, each with its own database. I want to use these modules' DbContexts in my central application, but we couldn't connect two different DbContexts in the same LINQ query. However, a YouTube video suggests it's possible. How can this be achieved?
-
0
hi
but we couldn't connect two different DbContexts in the same LINQ query.
I don't think this can be done.
https://github.com/dotnet/efcore/issues/32872#issuecomment-1910570373
-
0
-
0
Hi @IbrahimSarigoz,
Did you use the same interface in your EfCoreIletisimRepository? It should like;
public class EfCoreIletisimRepository : EfCoreRepository<IModuleADbContext, Iletisim, Guid>, IIletisimRepository { public EfCoreIletisimRepository( IDbContextProvider<IModuleADbContext> dbContextProvider) : base(dbContextProvider) { } }
Lastly don't forget the add repository to your ModuleNameEntityFrameworkCoreModule class.
public class ModuleAEntityFrameworkCoreModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { context.Services.AddAbpDbContext<ModuleADbContext>(options => { options.AddRepository<Iletisim, EfCoreIletisimRepository>(); }); } }
-
0
I completed all of these. If you want, I can share the github repo with you.
-
0
No need, I created a sample application that you can check out in abp-samples. Before testing it, make sure to build the entire solution using the
dotnet build
command. Afterward, you can debug the SampleRepositoryTests in the EntityFrameworkCore.Tests project. -
0
Hello, thank you for your response
Currently, when the 'Contact' entity is in the same database and tablespace, everything works fine. However, we need to use a separate tablespace for this entity (module). When I create a different tablespace and attempt to use this entity in linq, I encounter the following error:
'Cannot use multiple context instances within a single query execution. Ensure the query uses a single context instance.' System.InvalidOperationException: 'Cannot use multiple context instances within a single query execution. Ensure the query uses a single context instance.
I did some research, and they say it doesn't work with different tablespaces or databases in one linq. I want to make sure that it also doesn't work in the ABP framework.
-
0
hi
The ABP framework also uses EF Core as a repository implementation. so, it doesn't work in ABP either.