ef-migrations

Read database during an entity framework migration (select query)

拈花ヽ惹草 提交于 2019-12-22 07:00:02
问题 I know I can use the Sql method to update data during a migration, and it works great for simple things that can be expressed in pure SQL. I also know I could use a Seed method but that would feel like a hack (the code I want to write has to be executed once, when the migration is executed). In my current case, I need to strip HTML tags from a column, and write that to a new column added in the migration. I already have a C# method that does exactly that. What I want to do, is iterate over

Changing Primary Key using Entity Framework Core Migrations

≯℡__Kan透↙ 提交于 2019-12-22 06:36:05
问题 I am trying to Change the Primary key of a table via Entity Framework Core Migrations: protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.DropPrimaryKey( name: "PK_Permissions", table: "Permissions"); } When I try to update the database I get the following error message: To change the IDENTITY property of a column, the column needs to be dropped and recreated. How can I update the database? 回答1: I have found a solution: This seems to be a bug in EF Core 1.1 I

Code-First Add-Migration keeps adding the same column

一笑奈何 提交于 2019-12-22 04:49:09
问题 My model contains, among other things, two properties that were added to the model class after its initial creation and migration. public sealed class SomeModel { ... other properties, which are fine. public int PropertyOne { get; set; } public int PropertyTwo { get; set; } } My most recent migration contains: public override void Up() { ... other table being created. AddColumn("dbo.SomeModel", "PropertyOne", c => c.Int(nullable: false)); AddColumn("dbo.SomeModel", "PropertyTwo", c => c.Int

How to setup EF6 Migrations with ASP.NET Core

心不动则不痛 提交于 2019-12-22 01:49:21
问题 I am trying to adopt Jimmy Bogard's ContosoUniversityCore project I would like to do code first migrations, but not sure how to properly set it up. I added Migrator.EF6.Tools to my project. When I run Enable-Migrations I get this error: Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation.Package.Automation.OAProject' in assembly 'Microsoft.VisualStudio.ProjectSystem.VS.Implementation, Version=14.1.0.0, Culture=neutral, PublicKeyToken

Where can I find the console or debug output from code executed in the package manager window?

你。 提交于 2019-12-22 01:47:12
问题 I'm using EntityFramework code first with migrations. From the package manager console, I'm running "update-database". This executes Configuration.Seed(context) which I have overridden. protected override void Seed(WebContext context) { Console.WriteLine("Console Test"); Debug.WriteLine("Debug Test"); Trace.WriteLine("Trace Test"); } Where can I find that output? Better yet, How do I output back to the package manager window? Thx, Dan 回答1: Where can I find that output? Sorry, but the quick

NuGet Package Manager Console Default Project dropdown is empty

偶尔善良 提交于 2019-12-22 01:33:07
问题 I recently upgraded to Visual Studio 2012 RTM Ultimate from MSDN. I'm using EF Code First Migrations to build my database in my app, and I recently added a new entity and want to scaffold the migration for it. To do this, you need to open the Package Manage Console window in VS, and type add-migration "some name here" . This will scaffold any changes to your database since the last time it was updated. The Problem This issue did not occur on VS 2012 RC The problem I'm encountering is the

Configure EF to not drop any tables in migration

吃可爱长大的小学妹 提交于 2019-12-21 23:24:16
问题 I am using EF migrations to dynamically create a database model at run-time. This can happen many times, sometimes modifying existing tables and sometimes not. As every time i do a migration I don't want to create a massive context containing all the DbSets on the whole database I just want to include the tables I'm currently modifying. I am doing the migration in the following way Type contextType = null; //This will be my dbcontext DbMigrationsConfiguration migratorConfig = new

EntityFramework Npgsql DbConfiguration doesn't work

五迷三道 提交于 2019-12-21 22:04:01
问题 Im trying to configure EntityFramework with Npgsql with code first. EntityFramework 6.1.3 Npgsql 3.0.5 Now, i want to set a custom configuration by a class, let's see: public class DbConfig : DbConfiguration { public DbConfig() { SetProviderFactory("Npgsql", Npgsql.NpgsqlFactory.Instance); SetProviderServices("Npgsql", provider: NpgsqlServices.Instance); SetDefaultConnectionFactory(new NpgsqlConnectionFactory()); } } and my context class: [DbConfigurationType(typeof(DbConfig))] public class

Azure Web App deployment slots with database migration

好久不见. 提交于 2019-12-21 20:31:44
问题 I'm currently running a webApp with several deployment slots (e.g. dev, staging, production). Every Slot is connected to a database (db_dev, db_staging, db_production). I want to deploy to the staging slot and then switch with production. How do database migrations fit in here? I mean, if i deploy a new build with db migrations to staging the db_staging gets updated. What happens if I switch the slots? Do the migrations get applied to db_production? What about downtimes? From my understanding

Merging migration entries in Entity Framework

*爱你&永不变心* 提交于 2019-12-21 09:09:15
问题 I have an Entity Framework 6 CF project that has a few migrations already in place. The model is now stable and there is no need to keep the migration history that already exists. Is there a way to reset the model and merge all migration commands into the initial migration? As an example, the first migration adds a column while the second migration adds a unique, non-clustered index. I now want to see all these changes directly in OnModelCreating rather than in separate migrations. 回答1: