Closed Feraccia29 closed 6 months ago
First of all, I can't observe what you do because the posted code is not runnable. Second, I don't think this is related to JADNC, because the error comes from EF Core itself. Google for it and you'll find various matches. Third, why would you pass ServiceLifetime.Transient, ServiceLifetime.Scoped
? Fourth, even if this would work in EF Core, you can't just pass a set of DbContext types and assume JADNC figures out what belongs where. You need to decide per repository which DbContext it should use by injecting the appropriate types and register things appropriately. See the MultiDbContext example.
Closing due to a lack of response. Please provide more information if you'd like this to be reopened.
SUMMARY
I have this project in .net 6 and I have to use two dbContexts to refer two different database. When I add them to jsonapi one is working well, while the other send this error at runtime (for example when calling a GET):
"Cannot create a DbSet for 'Model' because this type is not included in the model for the context."
If I invert the order in the list of dbTypes that I pass to AddJsonApi, then the one that previously worked now launch the error at runtime and the other works fine. So I can exclude that there's something wrong with dbcontexts or entities.
DETAILS
I'm using reflection cause it's a framework code loading plugins, but it seems to me that the reflection is working good and the error occours only at runtime. I'll provide my plugin's dbContext below. If you change the OrderBy with OrderByDescending you can see the error will change dbContext.
STEPS TO REPRODUCE
Here the code in my startup.cs:
Here my Interface that I use just to search them in plugins' assembly
Here my two dbContexts:
First
Second
And the entities in the contexts ahead: First
Second
SQL Code to recreate tables in db:
VERSIONS USED