ef-migrations

EF 4.3 Migration - how to produce a downgrade script?

六月ゝ 毕业季﹏ 提交于 2019-12-04 01:37:07
I have an issue which I could not find answer for across the web. I am using CodeFirst EF 4.3.1 Migrations with MsSQL. I have added several migrations and now I want to produce a script for upgrade/downgrade between two migrations. For upgrade I run the following command which successfully reproduces an upgrade script: PM> Update-Database -Script -SourceMigration:"201205161144187_AddPostAbstract" -TargetMigration:"201205161203310_BlogLimitsAndTableRename" However, for downgrade I run the following command which fails with the following error: PM> Update-Database -Script -SourceMigration:

VS 2015 ASP.NET Web API (EF6) & Xamarin Enable-Migrations fails

一曲冷凌霜 提交于 2019-12-04 00:21:23
I'm developing a project that will use ASP.NET Web API as the data service, and a Xamarin portable app as client. I'm trying to enable migrations in the web app, but I get the following error: Enable-Migrations -enableautomaticmigrations -ContextTypeName MyProject.Models.ApplicationDbContext -ProjectName MyProject -StartupProjectName MyProject.App -Verbose Using StartUp project 'MyProject.App'. Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject' in assembly 'Microsoft.VisualStudio.ProjectSystem.VS

EF AddOrUpdate Seed does not Update Child Entities

拟墨画扇 提交于 2019-12-03 23:25:00
I'm having some issues Seeding data and I was able to reproduce the issue with a very small application. Given you have this Seed Method: protected override void Seed(JunkContext context) { context.Junks.AddOrUpdate(x => x.Name, new Junk() { Name = "BANANAS!!", Item = new JunkItem() { Name = "APPLES!!!" } } ); } when you run update-database in the PMC all of the entities get created successfully. Good. But when you wish to go and update the database, say your seed method is now this: protected override void Seed(JunkContext context) { context.Junks.AddOrUpdate(x => x.Name, new Junk() { Name =

Why I can't get Entity Framework Migration to initial state?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 21:14:47
I have deleted development database, and Migrations folder from project. When running unit test with use my project development database is recreated. I don't understand why running update-database gives me PM> Update-Database Specify the '-Verbose' flag to view the SQL statements being applied to the target database. Applying code-based migrations: [201302201840012_wieleDoWielu]. Applying code-based migration: 201302201840012_wieleDoWielu. Why migration: 201302201840012_wieleDoWielu is remembered ? How Can I delete it? Where is stored? Best Regards Przemysław Staniszewski Here's a answer.

EF Core Error - No project was found. Change the current working directory or use the --project option

允我心安 提交于 2019-12-03 19:11:16
问题 I am using Visual Studio 2015 and dotnet core and trying to develop an EF Core Code First project using Sqlite and this documentation / tutorial, which also uses Sqlite => NET Core - New Database When I try to add an initial migration from the command line ( I am CD-ed into the folder that my data model project is located in) by issuing the following command dotnet ef migrations add InitialMigration ...I get the following Error. No project was found. Change the current working directory or

Entity Framework Migrations renaming tables and columns

一世执手 提交于 2019-12-03 17:55:37
问题 I renamed a a couple entities and their navigation properties and generated a new Migration in EF 5. As is usual with renames in EF migrations, by default it was going to drop objects and recreate them. That isn't what I wanted so I pretty much had to build the migration file from scratch. public override void Up() { DropForeignKey("dbo.ReportSectionGroups", "Report_Id", "dbo.Reports"); DropForeignKey("dbo.ReportSections", "Group_Id", "dbo.ReportSectionGroups"); DropForeignKey("dbo.Editables"

EF 5.0 Enums Not Generating

拟墨画扇 提交于 2019-12-03 16:55:46
BACKGROUND I'm using VS 2010 on a machine where I installed .Net 4.5 which I've read was an in-place install (overrode the .net 4.0 version). I have projects still targeting 4.0 and 4.5 option is not available but was told it's ok since 4.5 was an in-place install. I then installed EntityFramework -pre via nuget and notices when I ran Upgrade-Database -Script commands, it would not generate enum properties. I then found this . I tried doing everything from scratch again but it was still adding EntityFramework 4.4 instead of 5.0. So I manually changed all references to point to the 5.0 version

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

有些话、适合烂在心里 提交于 2019-12-03 16:54:06
问题 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

EF 7 Migration to Existing Database

别说谁变了你拦得住时间么 提交于 2019-12-03 16:11:29
I am working on a web project using ASP.Net 5 and EF7. I have imported all the tables from existing database onto my models in my project. However, I am having problems in regards with migrations. I have created the initial migration, made some changes on particular entity, create another migration following the changes I have made and now want to apply the changes on the database. After running this command below: dnx ef database update [Migration] the dnx is trying to apply the 'initial' migration with all the entities which are already in database and this causes an error as below: { There

Manually Provide DbContext to DbMigrator

我是研究僧i 提交于 2019-12-03 15:42:05
Platform .NET 4.5 and Entity Framework 6. Question I have the following code to execute a Migration: //The following function just returns an object of the Configuration() class //generated by code migrations var migratorConfig = currentMigrationProvider.CreateDbMigrationConfiguration(); var dbMigrator = new System.Data.Entity.Migrations.DbMigrator(migratorConfig); dbMigrator.Update(); The problem is that Update() function tries to create an instance of my DbContext class and for a few good reasons I need to manually create the context and feed it to dbMigrator. Is that possible? How? Yes it