Search code examples
aspnetboilerplate

How Do I Use an Additional DBContext?


I have an existing ABP 1.0.0 project that connects to SQL Server. Now I'm trying to extend this app to get additional data from Teradata. I created a new EF project and referenced Teradata.Client.Provider instead of EntityFramework.SqlServer.

In the new project, I have a new TdContext class that has both desired DbSet Teradata entities, a model builder that maps the entities to the schema/table and the usual public constructors where I specify the connection string. I'm not sure the providerName so I guessed "Teradata.Client.Provider".

When I call the App Service that attempts to inject the IRepository<ATerraDataTable>, ABP throws the generic An Error has Occurred.

I'm not sure what is failing. Aside from the providerName, I can't find anywhere in ABP where I tell it to instantiate the Teradata client. Furthermore, I cannot remember how an IRepository<TEntity> knows which DbContext to use.

My injected IRepository<ASqlDataTable> works fine. When I wrote this solution 3 years ago, I only had the one DBContext to SQL Server, I didn't put much thought into asking how does an Repository know what connection to use. The ABP docs infer that the UOW does this but they don't go into enough detail for me.

.NET Provider for Teradata reference: https://downloads.teradata.com/doc/connectivity/tdnetdp/14.11/webhelp/DevelopingNetDataProviderforTeradataApplications.html


Solution

  • Abp 1.0.0 is old so i am not sure if my answer will be correct. But here goes.

    Abp uses a module system.

    if you look at your front end application(if mvc) you will find this class. appnameWebMvcModule.cs in the folder startup.

    In that class you will find the following line [DependsOn(typeof(xxxx))] where xxx is a other project. You can follow that chain until you reach appnameEntityFrameworkModule.cs Wich has the following line.

    Configuration.Modules.AbpEfCore().AddDbContext....


    If your second dbcontext is referencing a other database with a complete other structure, i would create a seperate application and implement a api. Then have your current application implement that api. this way you don't break any application and have and easier extensiblity.