ef-migrations

ASP.NET MVC 4, Migrations - How to run 'update-database' on a production server

僤鯓⒐⒋嵵緔 提交于 2019-12-03 04:14:51
问题 I can use package manager to run 'update-database -verbose' locally. Probably a stupid question but I can't find it online - once my website is deployed - how can I run this manually on the server? Secondarily - what other strategies would you recommend for deploying database migrations to production - and how would they be preferable? Thanks 回答1: You have a couple of options: You could use update-database -script to generate the SQL commands to update the database on the server You could use

Is it possible to change the location of the EF Migrations “Migrations” folder?

☆樱花仙子☆ 提交于 2019-12-03 03:31:11
问题 By default, the add-migration command attempts to create the migration .cs file in Project Root Migrations I'd like to store my migrations along with the rest of my EF-related code in the \Data folder of my project: Project Root Data Migrations With this structure, when I execute PM> add-migration Migration1 in the NuGet console I receive the following error: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\MyProjectRoot\Migrations\201112171635110_Migration1.cs'. at

EF - Moving from AutomaticMigrations to Manual Migrations

 ̄綄美尐妖づ 提交于 2019-12-03 02:26:41
End of long day of testing various scenarios where I don't have to recreate a production database... We started off with EF, and didn't get wise enough during development to move from automatic migrations to named migrations. Now I'm trying to rewind the clock, and create an initial migration that aligns with the production database. Is this possible to align a model has with an automatic migration has in the migration table? Should I just create an empty migration to get started with named migrations? My only problem with this is how to create the DB when a new developer joins... I could

Add database trigger with Entity Framework Code First Migrations

徘徊边缘 提交于 2019-12-03 02:04:31
I use Entity Framework Migrations for code first to control my database model. It works charming and I can handle until now everything. But now I need to add one database trigger and I would like to do this with EF Migrations and not use a separate sql script for only this case (This would be confusing for clients, esp. after we convinced them that we can handle everything with EF Migrations). My trigger is straight forward and looks like tis: CREATE OR REPLACE TRIGGER [name] BEFORE UPDATE ON myTable ... Is there a command to add a trigger to EF Migrations? You can just add a Sql("SQL COMMAND

EF Code First MigrateDatabaseToLatestVersion accepts connection string Name from config

拈花ヽ惹草 提交于 2019-12-03 02:03:35
While trying to implement EF Migrations in my project I am stuck at one place. EF Code First MigrateDatabaseToLatestVersion accepts connection string Name from config. In my case database name get known at Runtime (User selects it from dropdown). Just the way DbContext either accepts, ConnectionString or connectionString Name in it's constructor, "MigrateDatabaseToLatestVersion" does not accept the same System.Data.Entity.Database.SetInitializer (new MigrateDatabaseToLatestVersion<SrcDbContext, SRC.DomainModel.ORMapping.Migrations.Configuration>(connString)); Is there any other way to achieve

EF6: Renaming namespace using Code First Migrations

柔情痞子 提交于 2019-12-03 01:07:55
It is possible for me to rename the namespace of my entire Project (including of course: DbContext class, Migrations configuration classes, etc) without breaking anything or having to recreate all my migrations? Say, I have Project MyProject, which namespace is Foo.MyProject And my configuration classes are in Foo.MyProject.Migrations Say I want to rename Foo namespace for Bar , and of course my Configurations namespace now will be Bar.MyProject.Configurations Is there any correct way of doing this and maintain all my current Migrations still working? Do these ways involve manually editing the

Getting Initial Entity Framework Migrations Script

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 23:48:32
I just installed Entity Framework Migrations, added a property to a class, and gave EF Migrations a whirl. My development database was promptly updated. So far, so good. Now, I want to create a change script for this initial use of Migrations for the production database. Note there was a pre-existing database because I applied this to an existing project. The migrations I have are: PM> Get-Migrations Retrieving migrations that have been applied to the target database. 201204102238194_AutomaticMigration 201203310233324_InitialCreate PM> I thought I could get a delta script using the following:

How do I force Entity Framework to mark a particular migration as having been applied?

自作多情 提交于 2019-12-02 23:12:52
I'm using Entity Framework 5 in a project, and I've got Migrations enabled. Here's the scenario: A new developer (dev1) comes on and builds the project from source. There are existing migrations since previous developers had been working on the project in the past. When that developer runs the ASP.NET MVC project for the first time, the database builds automatically, and no errors appear. After that, however, a different developer (dev2) adds a new migration. When Dev1 tries to run Update-Database , all of the previous migrations are attempted to run. But they have already been applied, since

XML columns in a Code-First application

陌路散爱 提交于 2019-12-02 22:53:16
I'm trying to create an XML column in Code First. I'm well aware Entity Framework doesn't fully support XML columns, and that it reads them as a string. That's fine. I would still like the column type to be XML, though. Here's my class: class Content { public int ContentId { get; set; } [Column(TypeName="xml")] public string XmlString { get; set; } [NotMapped] public XElement Xml { get { ... } set { ... } } } Problem is, that Code First Migrations completely ignores the Column attribute and creates the field as an nvarchar(max) . I tried using [DataType("xml")] , but that, too, didn't work. Is

Add new table to an existing database using Code First approach in EF 6 and MVC 5

扶醉桌前 提交于 2019-12-02 18:35:26
I know this should be simple, but I was unable to find correct tutorial or explanation on web on this subject. There is a lot of videos and posts about adding new column to an existing table, using code first approach, but I can not find any with step by step explanation on how to add whole new table into existing database. Which is weird, I was pretty sure that I will find many examples. Maybe my search criteria is bad. So if anybody has any good link or video, please share. What I'm trying to do is to add table Post into existing Default Database, created by MVC 5 project. I've made model