Migrations and Update Database in Entity Framework for Dynamic connection string - entity-framework

I'm having 2 databases one for managing clients and other for managing application data. I'm trying to implement multi-tenancy application using EF code first approach where the database will be created on the fly it doesn't exist. Now tenant databases are creating fine but, database migrations are not performing since the connection string is passing programmatically. Please tell me how to do Database migrations for tenant databases where the connection string are set programmatically at runtime.
Thanks,
Naveen

Check out IDesignTimeDbContextFactor<T>
Microsoft doc: https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.design.idesigntimedbcontextfactory-1?view=efcore-2.1
Example: https://www.benday.com/2017/12/19/ef-core-2-0-migrations-without-hard-coded-connection-strings/

Related

Entity framework core code first migration postgresql database privileges management

I need to set up an automated way to manage table privileges and ownership during migration execution.
Currently, the workflow is that a developer runs database migrations using his personal account during the new version release. The issue here is that he is automatically set as the owner of newly created tables, and the owner and privileges for table access have to be changed manually afterwards. I'm looking for a way to automate this, but could not find a solution. My assumption is that this is not supported by ef core as permission/ownership handling differs on underlying database used, but I don't see a reason for specific ef providers not to have this functionality. I'm probably missing something obvious and any help would be appreciated.
We are using .NET 5 with EF Core 5.0 with Postgresql.

How to create a hibernate view of other databases?

Good Morning, I'm in a problem!
My project is multitenant, I use SPRING JPA + SPRINGBOOT + POSTGRES.
Where it contains a database manager and Each tenant has its own database.
The problem starts when inside the database of the tenant I have views of the data manager database.
For example, inside the database manager I have information to make the login of the users of a tenant. But in the database of each tenant should be able to have the information of their users. Where users within the tenant database could have more data!
What is the best way to do this? Should I create the view?
In addition, this application is very popular, so the idea is that the use of the database is quite dynamic.
Thank you in advance! any contribution will be helpful.
Yes the best solution will be to create views where you get all the data that you need and the data is already filtered for the tenant.
Edit:
You have to create the views on the database and then map it to read only Entities or just use it with SQL.
To have read only entities you can use Hibernates #Immutable annotation.
Please find more information in the Hibernate documentation: https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#entity-immutability

How do I best deploy Entity Framework migrations to a web farm

I have an application that uses Entity Framework code first migrations where the application is deployed on two servers both using the same database. Now I have a simple database update where a table and the EF model has a new column/property. I have created the migration and it works fine in a one server scenario.
But how do I deploy this to two servers without downtime? Without EF I would just start out and add the column to the table and then update the servers one by one. The old app would work just fine against the updated database as long as it is a simple change like this. What is the best way to do this in EF? Can I avoid problems in the second, not updated server, while I am updating the first one and the database?
This sounds like a perfect candidate for a Mirrored database, assuming you are using SQL Server.
You'd just apply your migrations to the Principal database and it will take care of the rest behind the scenes.

Entity framework code first - work with existing empty database

Working on EF Codefirst 5.0, on deployment we created the empty database in order to create the username and permission level settings, because in the database server this user is specific to only this database.
so we done above steps and tried to run the application, it throws below exception as it was not created by the EF code first, any solutions for handling this scenario?
help on this really appreciated.
Error:
Model compatibility cannot be checked because the database does not contain model metadata. Model compatibility can only be checked for databases created using Code First or Code First Migrations.

ASP.MVC2.0/EF4.0 site deployment/maintenance

My small team used asp.mvc 2.0/entity framework 4.0(model first approach)/Windows Server 2008r2/Sql Server 2008 r2 stack in out web site project. We've already complete developing process, and come to the web deployment stage. In this stage we are faced with the problem - ok we'll use vs2010 features for initial server/db deploy, but what we'll do in the future? Obviously some of our models can be modified after publishing in order to satisfy new conditions, and of course our server db will contains users data sets, articles etc. Is there any approach to update servers db with new db modification, without dropping db, and converting data from old instance to the new one?
Now we have found only DAC/DACPAC approach to update server db, but we don't know how to bind auto EF model generation with DAC.
May be there is exists another solution? Is there any standard way to resolve this kind of situation? Any advice?
Thanks
I'd be interested to know if you have found a solution to this yet?
Have you tried simply generating a database based on your EF model, and using a schema comparison tool such as SQL Compare to deploy changes from the EF-generated database and your target production server?