Deploying entity infrastructure code first with a production database

I developed a fairly simple web application using entity code first. I realized after several hours of frustration that, although localdb is SQL Server Express, it is not really intended to be used to create a publish (publish wizard). FYI I am using EF 6.1.3, SQL Server 2014, VS 2013 and IIS 7.

If I understand correctly when you click publish from localdb, all you really do is copy the localdb database to your IIS 7 server. I couldnโ€™t understand why, when I updated my lodaldb database through VS migrations, what The base of my production server was not updated. I understand (and believe that now) that these are actually two different instances of localdb and therefore not the same data.

OK, whatever I do - I did with localdb, and I created a real SQL Server 2014 db on my machine. I googled for many hours and can't figure out what to do now. I have a few questions:

  • How to manage this new database using EF? For example, suppose I want to add a new column. First I add it to my localdb, do some tests and do the migration using Add-Migration blah, then Update-Database ... Should I then generate a SQL script using VS, and then manually run it in the production database server?

  • I know that this is not very convenient, but instead of using a local database with an entity infrastructure, can I just bind EF to a real SQL Server intermediate test database and skip all this localdb bull *** *? Then could I control it with the first transfer codes and keep everything in sync?

  • Should I use Initializer? I read conflicting posts about whether to use these or not for production db (like this one)

    public class PricedNotesInitializer: MigrateDatabaseToLatestVersion <...,... > { }

, - , . , .

.

+4
4

SQL express edition , SQL. SQL SQL Azure .

A 1. local connection string production package manager. .

PM> Update-Database

A 2: .

A 3: :

 Database.SetInitializer(new CreateDatabaseIfNotExists<YourDbContext>());
+3

: localdb SQL-.

, , add-migration update-database localdb.

, , , . . update-database. , .

+2

MigrateDatabaseToLatestVersion, ( ) , .

, . .

, , LocalDB , , ( ) , .

" " , , .

- , , .

- / , .

, , - ;)

, - , , . , script it , , , (, , , ).

+2

. , . , , . , . . , , db :

  • VS2013 โ†’ sql server object explorer โ†’ (LocalDb)\v11.0 โ†’ โ†’ [__] โ†’ โ†’ โ†’
  • SQL , , .

  • compare โ†’ Update Target ( , db-db, )

  • SSMS (SQL Server Management Studio), . !

  • , , , CreateDatabaseIfNotExists -, . , , , , .

  • -, , -, , , , ( localdb ). . , .

  • ! DB SQL Server Express.

, . , , .

0
source

Source: https://habr.com/ru/post/1654703/


All Articles