ef-migrations

Entity Framework Core 2.0 - Run migrations step by step

和自甴很熟 提交于 2019-11-27 04:47:07
问题 In EF6 I could retrieve migrations and run it step by step. Is there a way to do something similar in EF Core? EF 6 Code public static void RunMigration(this DbContext context, DbMigration migration, string providerName, string manifest) { var prop = migration.GetType().GetProperty("Operations", BindingFlags.NonPublic | BindingFlags.Instance); if (prop != null) { IEnumerable<MigrationOperation> operations = prop.GetValue(migration) as IEnumerable<MigrationOperation>; MigrationSqlGenerator

EF 4.3.1 Migration Exception - AlterColumn defaultValueSql creates same default constraint name for different tables

蓝咒 提交于 2019-11-27 04:43:30
问题 I have a DB that I created using the OOB database initializer, and I am using Code First with EF 4.3.1. I wanted to take advantage of the new "IgnoreChanges" flag on the Add-Migration cmdlet, so that I can alter some of my columns and add a default SQL value. Essentially, some of my entities have a column named DateLastUpdated, which I would like to set the DEFAULT to the sql expression GETDATE(). I created the InitialMigration using "add-migration InitialMigration -ignorechanges", and then I

Enable-Migrations installation error

99封情书 提交于 2019-11-27 03:56:23
问题 I'm running into a problem when enabling migrations on one of my projects. I execute Enable-Migrations command from the Nuget Console and receive an error saying: Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.TeamArchitect.ModelingProject.ModelProjectAutomationObject' in assembly 'Microsoft.VisualStudio.TeamArchitect.ModelingProject, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable." At D:\Solution\packages

EF5 Code First - Changing A Column Type With Migrations

孤人 提交于 2019-11-27 03:56:04
I am new to EF5 Code First and I'm tinkering with a proof-of-concept before embarking on a project at work. I have initially created a model that looked something like public class Person { public int Id { get; set; } public string FirstName { get; set;} public string Surname {get;set;} public string Location {get;set;} } And I added a few records using a little MVC application I stuck on the top. Now I want to change the Location column to an enum, something like: public class Person { public int Id { get; set; } public string FirstName { get; set;} public string Surname {get;set;} public

How to use migration programmatically in EntityFramework Codefirst?

混江龙づ霸主 提交于 2019-11-27 03:52:37
问题 I'm working in a project that uses EF Code First. I'm trying to use migration features. I don't want to use Package Console Manager. How can I execute the "Add-Migration" and "Update-Database" programmatically? add-migration TestMigration01 -force update-database 回答1: You have a couple of choices. You can use the dbmigrator class from within your code: http://romiller.com/2012/02/09/running-scripting-migrations-from-code/ Or you can use migrate.exe which is handy for running them in a build

Enable Migrations with Context in Separate Assembly?

好久不见. 提交于 2019-11-27 03:00:39
I have one project that I want to run my update-database against but I have my Models and Context in a separate project. If I run enable-migrations I get this error: No context type was found in the assembly 'MyProject'. This is presumably because my Context is in MyProject.MVC. If I run enable-migrations against MyProject.MVC I have to add an app config file. I don't want to do that as I want to use the code across many projects. So can I run enable-migrations against MyProject and somehow tell it to look in MyProject.MVC for the Context? This will only work in EF 6, but there was a release

EF 5, Code First - Create a new database and run all migrations programmatically

家住魔仙堡 提交于 2019-11-27 02:19:57
问题 I'm using Entity Framework Code First migrations, and I have a scenario where I want to run a suite of integration tests. Each time the tests run, I want to re-create the database, and apply all migrations The steps should be: Drop the existing test database (if any) Create a new test database, and apply all migrations Seed data This is an existing project that I've added migrations to, and I used the Enable-Migrations command to create an "InitialCreate" migration that contains code to add

How to run Seed() method of Configuration class of migrations

时光总嘲笑我的痴心妄想 提交于 2019-11-27 01:45:02
问题 I have 2 questions: 1) How can I run Seed() method from the package-manager console without updating-database model? 2) Is there a way how to call Seed() method in the code? Thx for any advice. 回答1: Answering your first question. Create a Migration by running add-migration SeedOnly Clear out all Up() and Down() code generated if there was any pending changes public partial class SeedOnly : DbMigration { public override void Up() { } public override void Down() { } } Then you can Target a

How to ignore a table/class in EF 4.3 migrations

纵然是瞬间 提交于 2019-11-27 01:25:05
问题 I'm testing with EF 4.3 (beta) I have some new classes which should generate db tables and columns. From a old project i have some old tables in my schema, which i want to access via EF. All Classes are declared. For accessing the old table, there is a poco which is mapped. The db migrations tries to create that old table, too. How can it set that this class/table is not part of the migration, but part of the ef model? xxx.OnModelCreating() { modelBuilder.Ignore<myOldTableClass>(); } removes

How to seed data with many-to-may relations in Entity Framework Migrations

≯℡__Kan透↙ 提交于 2019-11-27 01:08:13
问题 I use entity framework migration (in Automatic migration mode). Everything is okay, but I have one question: How should I seed data when I have many-to-many relationships? For example, I have two model classes: public class Parcel { public int Id { get; set; } public string Description { get; set; } public double Weight { get; set; } public virtual ICollection<BuyingItem> Items { get; set; } } public class BuyingItem { public int Id { get; set; } public decimal Price { get; set; } public