ef-migrations

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

本小妞迷上赌 提交于 2019-12-03 09:04:56
问题 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

How to add a new code-first migration with a newly-generated database?

ε祈祈猫儿з 提交于 2019-12-03 08:59:30
I've enabled code-first migrations on my entity framework project, and have added several migrations which do things like rename tables. However, I have now deleted the database and caused entity framework to generate a brand new database based on my latest data model. If I try to run: PM> Add-Migration TestMigration ... it tells me that I need to apply the existing migrations first. So I run: PM> Update-Database ... but the trouble is that it's trying to update a database that doesn't need updating; it's already based on the latest data model. So I get an error when it tries to rename a table

Generating seed code from existing database in ASP.NET MVC

蹲街弑〆低调 提交于 2019-12-03 07:09:35
I wondered if anyone has encountered a similar challenge: I have a database with some data that was ETL'ed (imported and transformed) in there from an Excel file. In my ASP.NET MVC web application I'm using Code First approach and dropping/creating every time database changes: #if DEBUG Database.SetInitializer(new DropCreateDatabaseIfModelChanges<MyDataContext>()); #endif However, since the data in the Database is lost, I have to ETL it again, which is annoying. Since, the DB will be dropped only on model change, I will have to tweak my ETL anyway, I know that. But I'd rather change my DB seed

How to create a clustered index when using code-first migration with Entity Framework and SQL Server

南笙酒味 提交于 2019-12-03 06:08:19
问题 I have a MessageModel with a timestamp attribute of when the message was created. I would like to make a clustered index on this long attribute. I hope to achieve a query speed-up when doing a query to get all messages newer than a certain timestamp. The timestamp value is never changed after creation. I currently have a regular index on a int Id attribute. How can I add a clustered index on a models attribute using Entity Framework code-first migration in ASP.NET MVC 4.5? 回答1: UPDATE :

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

感情迁移 提交于 2019-12-03 06:01:34
问题 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

Entity Framework Code-First Migrations - Cannot drop constraint because it doesn't exist (naming convention from 4.3 to 5.0)

五迷三道 提交于 2019-12-03 05:50:14
Was previously using EF 4.3 and upon upgrading to 5.0 I find out the Indexes, FK constraints, and PK constraints all have had their naming conventions changed to include dbo (eg. PK_Users has now become PK_dbo.Users) Now anytime I make a change to the model and it needs to change a table that has these in it, it always says it can't drop constraint because it can't find it. I just want it so that when it tries to drop a constraint/index/key it first checks to see if the pre-5.0 naming one exists and if so drop it, but still re-create it using the new 5.0 naming conventions. The naming

Consolidating EF migrations into new InitialCreate

你说的曾经没有我的故事 提交于 2019-12-03 05:30:00
问题 I have been using EF migrations for some time now and have more than 100 migration files in my project. I would like to consolidate these into a single migration before moving forward - ie I want to replace the existing InitialCreate migration with a new version that takes all my subsequent changes into account so I can then delete all the other migration files. I do this very easily if I am not concerned with losing all the data in the DB, but I am. How can I achieve this whilst keeping all

Update-Database tries to do an automatic migration even with automatic migrations disabled

℡╲_俬逩灬. 提交于 2019-12-03 05:04:16
问题 I work on a team of 4 developers using EF5, everyone working on their own local database. Up until now we've been using automatic migrations but we're nearing the point where we need to release to production so we've disabled automatic migrations and started adding explicit code-based migrations. Here is the problem: I ran the Update-Database command after a developer created a new explicit migration and I get the following error: Applying code-based migrations: [201209080142319_CreatedDate

EF Code First - Timeout expired. The timeout period elapsed prior to completion

十年热恋 提交于 2019-12-03 04:40:38
Apology for this strangely worded question. I don't know what the actual problem is but hopefully someone can give me some insights. I am getting the following error when trying to run migrations: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out It is interesting to note that on my laptop this is not happening but on my VM (azure - large) this is happening with 100% failure rate. I am using Ef 6.0.0 -rc1 . Please note, updating EF is not an

update the database from package manager console in code first environment

有些话、适合烂在心里 提交于 2019-12-03 04:16:27
问题 Code First Environment I'm trying to update the database from package Manager console.If my Domain class change, I have to drop and create the database,Instead of dropping the Database how can i update the database. I have already try by reading some blogs in google. commands PM> Install-Package EntityFramework By using this command i install the Entity Framework successfully. PM> Enable-Migrations By using this command it created the Migration file in my project. PM> Update-Database By using