ef-migrations

Entity Framework 4.3 Migrations move existing data

◇◆丶佛笑我妖孽 提交于 2020-01-03 10:40:51
问题 I'm using EF Code First 4.3 Migrations to update my database scheme. Now I have the following situation: table A needs to be removed, table B must be created and the data of table A must be copied (along with some other data) to table B. I do not have access to the DbContext in the DbMigration class, my question is how to implement this? 回答1: In migration Up method of your migration you can use Sql method to define any SQL you need so if you use explicit migration you can put data migration

Entity Framework change Key Type

一笑奈何 提交于 2020-01-03 08:37:12
问题 I have created a model with various values but stupidly used a GUID for my key, I am currently attempting to change that to an Int but am getting an error when I do so. I have run the enable migration command: Enable-Migrations -Force -ContextTypeName project.Models.MyContext This creates the migration I would expect but when I run: Update-Database -Force The error I'm getting is: Operand type clash: uniqueidentifier is incompatible with int I don't care about the data currently contained

Data Migration In MVC3 (Using EF.4.3)

十年热恋 提交于 2020-01-02 10:30:48
问题 I am doing data-migration for my project. But I have one question, for example: I have Book table with following fields: ID Name Color 1 Java red 2 MVC blue 3 .Net blue I tried to change the name of field from "Color" to "BookColor" using Code First tech. But after migration the table looked like this: ID Name BookColor 1 Java null 2 MVC null 3 .Net null I lost my field values. How can I make sure that all value are transfered? I'm using Entity Framework with MVC3 EDIT This is my DBMigration

Is that possible to have a single DbContext, with migration files being split in different assemblies?

天涯浪子 提交于 2020-01-02 07:00:10
问题 I've built a system which have a Core solution and a Custom solution for each of our clients. The Core has it own dbcontext, and each Customs have their own dbcontext for client specific tables. Custom solution is referencing Core solution dlls. Custom dlls are being dynamically loaded by the Core solution in a plugin architecture. Since Core and Custom have their own dbcontext, each one have their own migration files. All is working pretty well except for one thing, i cannot make a linq

System.Resources.MissingManifestResourceException when Updating database

陌路散爱 提交于 2020-01-02 01:13:16
问题 I moved a web application I am working on from one machine to another. It is built using .Net MVC and Entity Framework but when I execute the Update-Database command so that the database is updated, I get this error: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "NameofMigration.resources" was correctly embedded or linked into assembly "NameofProject" at compile time, or that all the satellite assemblies required are loadable and fully

EF Code First Migrations: MigrateDatabaseToLatestVersion without NUGET

不问归期 提交于 2020-01-01 08:22:13
问题 I need help to clarify how EF Code First Migrations works on production machine. I've some entity classes and DbContext-derived class to access entities. Now, I want to perform these several things: when my application starts, it must create database, if database does not exists; then database schema must be adjusted to the model; if database was created just now, I want to create some indexes; also, if database was created just now, it must be seeded by some initial data; all of these things

Net Core 2 - Entity Framework: Update-Database of different environment

余生颓废 提交于 2020-01-01 03:36:10
问题 FACTS: net core 2.0 project entity framework (code first) different appsettings.json file for different environments I utilize Package Manager Console to generate my DB scripts (Add-Migration, Update-Database) If I run PM>"Get-DbContext" it brings back info pulled from my appsettings.Development.json file GREAT, that's what I want most of the time! But how do I tell it to pull db variables from appsettings.Staging.json instead of development for PM commands? I tried creating new

Entity framework code first migrations, sql user permissions?

荒凉一梦 提交于 2019-12-31 21:22:50
问题 What is the minimal permission needed on a sql server user/login for it to be able to run entity framework code first database migrations? I naively would have thought that a user with the roles db_datareader, db_datawriter, Grant Alter on the Schema and Grant Create Table would be permissive enough. 回答1: you need following permision on the database. [db_datareader] [db_datawriter] [db_ddladmin] For full control over database use [db_owner] 回答2: Clearly it depends on what your migrations are/

Entity framework code first migrations, sql user permissions?

 ̄綄美尐妖づ 提交于 2019-12-31 21:22:12
问题 What is the minimal permission needed on a sql server user/login for it to be able to run entity framework code first database migrations? I naively would have thought that a user with the roles db_datareader, db_datawriter, Grant Alter on the Schema and Grant Create Table would be permissive enough. 回答1: you need following permision on the database. [db_datareader] [db_datawriter] [db_ddladmin] For full control over database use [db_owner] 回答2: Clearly it depends on what your migrations are/

EF 6.0 Migrations: ContextKey in MigrationHistory is null

China☆狼群 提交于 2019-12-31 17:37:28
问题 I've updated to EF6 and it hasn't been fun. I have created a new migration that is just changing two fields to nullable. public partial class AllowNullableFieldsForImage : DbMigration { public override void Up() { AlterColumn("dbo.Scabs", "image_height", c => c.Int()); AlterColumn("dbo.Scabs", "image_width", c => c.Int()); } public override void Down() { AlterColumn("dbo.Scabs", "image_width", c => c.Int(nullable: false)); AlterColumn("dbo.Scabs", "image_height", c => c.Int(nullable: false));