ef-migrations

EF6: Renaming namespace using Code First Migrations

坚强是说给别人听的谎言 提交于 2019-12-20 10:39:38
问题 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

Entity Framework Migrations - Enable AutoMigrations along with added migration

大城市里の小女人 提交于 2019-12-20 10:38:28
问题 I'm utilizing Entity Framework 4.3 Migrations in my project. I would like to use Automatic migrations so that when I make modifications to my domain objects and my context class, my database automatically updates when I run the project. I have this working so far. I would also like to use some Added Migrations in addition to the automatic migrations, and I would like the application to automatically jump to the latest version (based on my added migrations) when I run the application. In order

Performing an IDENTITY_INSERT using EF5 Code First Migrations

隐身守侯 提交于 2019-12-19 18:27:23
问题 I have a POCO that I am trying to create via Code First Migrations and then seed data. The problem is that I want to insert specific values into the identity column when seeding. Here is my POCO public class Result { public long ResultId { get; set; } public long? TeamId { get; set; } public Team Team { get; set; } } And here is my AddOrUpdate call in the Seed method of the Configuration.cs context.Results.AddOrUpdate ( r => r.ResultId, new Result { ResultId = 101, TeamId = null }, new Result

Entity Framework - How to get relative file path in seed method

孤街醉人 提交于 2019-12-19 05:47:40
问题 Why is filePath null? Any ideas on how to get the relative filePath? internal sealed class Configuration : DbMigrationsConfiguration<MvcProject.Models.FileDb> { public Configuration() { // code here is not relevant to question } protected override void Seed(MvcProject.Models.FileDb context) { string filePath = System.Web.HttpContext.Current.Server.MapPath("~/Content/File.txt"); // read File.txt using filePath and update the database } } I have the above code in Configuration.cs file in

Enabling Code First Entity Framework VS Web Express 2012

走远了吗. 提交于 2019-12-18 15:03:35
问题 I am trying to enable Code First in my Visual Studio Web Express 2012. From what I have read so far I have to use the Package Manager Console and the command Enable-Migrations. When I do this I get the following error. Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///E:\Working\wingtoysdl\C#\packages\EntityFramework.5 .0.0\tools\EntityFramework.PowerShell.Utility.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT:

How can I change an int ID column to Guid with EF migration?

做~自己de王妃 提交于 2019-12-18 14:47:39
问题 I'm using EF code-first approach and want to change the Id field to guid but can't seem to get past below error. This is my first migration: public partial class CreateDownloadToken : DbMigration { public override void Up() { CreateTable( "dbo.DownloadTokens", c => new { Id = c.Int(nullable: false, identity: true), FileId = c.Int(), UserId = c.String(nullable: false, maxLength: 128), ValidUntil = c.DateTime(nullable: false), }) .PrimaryKey(t => t.Id) .ForeignKey("dbo.Files", t => t.FileId)

error loading database initializer with EF6

与世无争的帅哥 提交于 2019-12-18 12:56:11
问题 I have been trying to follow this tutorial ... http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application but I keep getting the following error ... system.invalidoperationexception = {"Failed to set database initializer of type 'WeddingPreparations.Dal.WeddingInitializer, KevinLisaWedding' for DbContext type 'WeddingPreparations.Dal.WeddingContext' specified in the application configuration. See inner exception

EF Code First Migrations to Deploy Older Version

会有一股神秘感。 提交于 2019-12-18 12:22:18
问题 I'm using TFS Release Management to do continuous integration and deployment. I'm using migrate.exe to perform the database migration during deployment, and this works great when you're going from an older version to a newer version. When you want to deploy an older version of the application, however, it gets more muddy. Basically, the assembly that holds your migrations for a context must know how to go from say version 3 to version 2. Normally, you use the assemblies you're about to deploy

EF Code First Migration with Multiple Database / DbContext

三世轮回 提交于 2019-12-18 11:33:13
问题 I have two database each with their own dbcontext. I've setup two migration configurations. I can add a migration for the first db ust fine ( Add-Migration DB1_InitialCreate -ConfigurationTypeName DB1Configuration ). When I try to create an initial migration with the second db using: Add-Migration DB2_InitialCreate -ConfigurationTypeName DB2Configuration , I get the following error: Unable to generate an explicit migration because the following explicit migrations are pending:

Re-create table with Entity Framework 5 and nuget

情到浓时终转凉″ 提交于 2019-12-18 11:11:31
问题 I am using Code First to create a table. I created the class, the mapping file and issued the add-migration command in nuget and then the update-database command I then changed the class and like an idiot deleted the table. I deleted the migration class file I issued a add-migration command When I issue the update-database command I get the following error: System.Data.SqlClient.SqlException (0x80131904): Cannot find the object "dbo.CorrectiveActionPlan" because it does not exist or you do