How to use DbContextFactory in ABP? - entity-framework-core

Is there a possibility of using DbContextFactory and Repositories in the ABP Framework?
Or are there other approaches to insert rows into the database in parallel?

Related

Is there a way for implementing database migrations on Spring JPA without the use of frameworks (e.g.: flyway, liquidbase, etc)?

I'm migrating a system that used to be written in Jdbc Templates to Spring Data JPA. Before, we used to write the SQL queries ourselves, but now that we're modernizing our system, we're going to use Spring Data JPA for this. Due to restrictive factors, i can't implement a database migration framework, such as flyway and liquidbase. Is there any way i can implement those using what i have on Spring JPA?

How to create DB Context run time?

In my asp.net core application, each client has their own database schema.
Hence there are many databases. Sometimes the tables and fields will be different.
I have used Entity Framework core as ORM and we are following Generic Repository pattern.
Is there any option to generate DB Context at run time corresponding to each client?
Thanks
Krishnan

Liquibase from JPA classes, no database yet

We have started our application by our model classes, annotated with JPA annotations. We did not create any tables in the database yet.
Now, we would like to somehow generate a liquibase changelog by only looking at the JPA classes, maybe at file persistence.xml.
Most of the questions and answers about liquibase in SO suggest to run liquibase and compare it with the current state of the database. But that's not our case, because our database does not have any of the tables corresponding to the JPA entities, nor any of the liquibase control tables.
How do I generate a liquibase changelog file from the JPA entities?
you can take a look on liquibase-hibernate plugin https://github.com/liquibase/liquibase-hibernate/wiki
you can make a diff between your JPA entities against an empty database , and this will generate the whole changelog of the JPA entities..

Joining multiple tables from different databases

I am working on ASP.NET core application where I am using Entity Framework to interact with SQL server database. so far, I was using Scaffold-DbContext command to create new model from SQL server database. Even if , we wanted to create DbContext based on multiple tables, I could do that using -t flag in above command. Everything happening on single SQL database.
Scaffold-DbContext "Server=XXXXXXXXX;Database=XXXXXXXX;User Id=XXXXX;Password:XXXXXX" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -t Table1 Table2
From Scaffold-DbContext parameters commands, I couldn't find option to specify different databases.
In new scenario, I have to join 2 tables from different SQL databases. Is there a way to create model which is consist of 2 tables from different databases. Both tables are using one-to-one relationship between them.
For example- DB1 has table1 and DB2 has table2. Is there a way to create a DbContext which is consist of these 2 tables (table1 and table2)?
Is there any other way to achieve join between 2 tables from 2 different database?
No, you can't do that with EntityFramework (neither 6.x nor Core). A DbContext is per database and you can only do joins within the same DbContext.
You could create a view and map the view to the models you needs, but iirc. mapping of views is still on the roadmap for EntityFramework Core. May work with EntityFramework 6.x though.
Edit:
At least you can't doing it with Linq/Fluent api. You can execute raw queries though. The catch: The project must match the model exactly, there can't be any missing fields of the model. The Ad-hoc mapping to non-entities is on the roadmap for future versions of EntityFramework Core

Managing transactions using ADO.Net Entity framework - Update multiple databases

I need to update multiple databases in one transaction using entity framework. Means if we need to insert records in two tables of two different databases and insertion succeeds for first database but fails for other database then insertion in first database should also get rolled back.
Please let me know if we can do this using entity framework.
Thanks
Sharad Rastogi
Managing Connections and Transactions (Entity Framework)
You can use a TransactionScope to accomplish what you require.
How to: Manage Transactions in the Entity Framework
TransactionScope and ADO.NET Entity Framework