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

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.

Related

Adding and running EF core migrations for multiple applications using same DB

I have two different applications (two different solutions) using the same database. Each application has its own set of models/tables used in it.
The .NET solution for Application 1 was created a year back and has evolved till today. As part of this, some new models were created, migrations were added and updated in the database (SampleDatabase). This has its own DBContext class.
The .NET solution for Application 2 is a new one created a month back. This application also uses the same database (SampleDatabase). A few new models specific to this application were created, migrations were added and updated in the database. This has its own DBContext class.
Requirement:
Now, there is a requirement where one of the tables created and being used by Application 1 needs to be modified to integrate with Application 2 (i.e., a PK from an Application 2 table has to be placed as a FK in an Application 1 table.).
Challenge
To create a migration for altering the model from Application 1, a reference is needed to the PK table available in the other solution, which is not possible.
To create a migration for altering the existing model from Application 2, the existing model has to be copied to the Application 2 codebase. By doing so, if a migration is added, it generated only a CreateTable statement and not an alter as the DBContext does not know that the table already exists.
Question:
How do we manage to have migrations that is aware of things happening in the database from both the solutions?
Thoughts:
One way that I had in mind is to have a shared library project that can be responsible for all migrations to this database. Requirements for any application can be taken care by this project. But this has to refer the DBContext from both the application which is again a challenge.
Please let me know your thoughts and if anyone has faced such situation in your projects.
Thank You.

Core 2 Keep domain models in sync with database changes

Need help! I am new to Core 2.0 and VS 2017 and haven't had much experience with MVC. I have an existing database that I need to use with a core 2.0 project at work. I was able to use the Scaffold-DbContect to initially create the domain models from the existing database.
However, the database developers are making changes to the database and adding new tables. I need to keep my domain models in sync with the database changes that are being made.
The only thing I can find on the internet is how to make changes to the model and update the database schema. However, I need to update the model from changes made to the database.
EF Core works on Code First approach. And You guys are following DB First approach together. So you should make changes in your code and then generate migrations accordingly, Otherwise, it will lead you in trouble.
You can use EF Core Power tool for generating the db changes at code side. But in this case you have to take care while generating migrations from code side.

How do I create the database for IdentityManager and IdentityServer?

I have downloaded the samples from the IdentityServer3 github repo and ran the MembershipReboot project, I changed the connection string to point to a real server but I still don't see how to get it create the database, I thought this used EF code first to do this. I just feel lost right now trying to understand how to use IdMgr and IdSvr.
You were right, The IDS MembershipReboot project relies on MembershipReboot which in itself uses EF migration scripts to generate the database if it doesn't exist (or upgrade it if it's an old one).
But, note that you need the connection string to use a user with permissions to create the database and tables in it.
Also, as far as I can remember you need to actually hit the (IDS) server with a request to get things spin up and create the DB. Otherwise, IDS would not load anything from the IoC container and the DbContext would not get created. But this is something I cannot verify now.
The configuration database of IDS (scopes, clients, claims etc.) is stored in-memory in the MembershipReboot sample you are using. It could be stored in MSSQL using EF (or any other store if you care to implement it). You can see a working sample that uses EF and MSSQL in the EntityFramework sample project. I guess you can combine the two samples get what you are after.

Entity Framework Database Generation Power Pack?

I use Model-first with EF, and I want to have an automated gap DDL script when I change my model. With "Entity Framework Database Generation Power Pack" We had it in past, but I read that was not supported in VS2012.
Any changes about that?
For Who dont't understand this need, I would like to remmember that in production enviroments, development team dosen't have access to DB. We must create and send to production Support team, DDL deployment scripts that preserve data and all DB without any recreation.
You should have a look at Database.SetInitializer, which mainly determines what happens if there is no database present when the application is started for the first time, and migrations which can be used to update the datebase when a new application version (which requires an updated database) has been deployed. If the built-in support for migrations data aren't enough, you also have the ability to add raw SQL data to handle migrating to a new version.

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?