ef-migrations

Ignore pending migrations after database recreation

佐手、 提交于 2019-12-11 03:07:42
问题 We am using code first EF 4.3.1 with database migrations. Sometimes we drop the database and let EF recreate it, mainly for local development purposes. There is a procedure which applies pending migrations and when the database is recreated the pending migrations aren't necessary and error is thrown when EF tries to apply them. I check the migration date from the string and if this is before the database creation date then I manually add it to the __migrationHistory table and don't apply the

How to use SQL Server Views with EF Code First Migrations

会有一股神秘感。 提交于 2019-12-11 02:57:47
问题 I've reverse engineered a small database that contains a number of tables and views into EF 5 code first. When I do this, I get a set of models and mapping classes for each of my tables and these work well when I try to query the database using the generated DbContext . It also generates POCO classes for each of my views, but when I run Enable-Migrations and Add-Migration using the Package Manager Console, the migration does not re-create the SQL Server views. I have tried updating the

EF 4.3 Code First Migrations - Seed per migration

試著忘記壹切 提交于 2019-12-11 02:52:29
问题 have recently started using Code First Migrations and was wanting to seed data in each Up method. is this possible? Ie. Create database table Fill with data for Drop: Delete data from joining table delete table 回答1: Yes it is possible but you must do it through executing SQL commands. Use Sql method in both Up and Down methods of your migration to execute INSERT and DELETE SQL commands. 回答2: public partial class DBInitializer : IDatabaseInitializer<DBContext> { public void InitializeDatabase

Code migration unexpectedly tries to rename table

流过昼夜 提交于 2019-12-11 02:37:12
问题 I want to implement a change log as advised in Dev Express XAF T474899 I am using the security system generated by the XAF new solution wizard I have defined some business objects to store the change log information. One of these objects stores a link to the user public virtual User User { get; set; } On generating the code migration I am surprised to see the Up() method add the following RenameTable(name: "dbo.UserRoles", newName: "RoleUsers"); DropPrimaryKey("dbo.RoleUsers"); AddPrimaryKey(

How should I define a field that can take various data types in EF?

给你一囗甜甜゛ 提交于 2019-12-11 02:16:07
问题 My poco class is as follows; public class FilterParameter { public int Id { get; set; } [Required] public virtual UserFeatureSetting UserFeatureSetting { get; set; } [Required] [MaxLength(450)] public String ParameterName { get; set; } public object ParameterValue { get; set; } } but the generated migration code is not creating the ParameterValue field. CreateTable("dbo.FilterParameters", c => new { Id = c.Int(nullable: false, identity: true), ParameterName = c.String(nullable: false,

How to enable CodeFirst to migrate schema changes against a replicated database?

落爺英雄遲暮 提交于 2019-12-10 23:28:47
问题 Running any migration that alters existing replicated tables fails with the following error: You can only specify the READPAST lock in the READ COMMITTED or REPEATABLE READ isolation levels. Have tried taking the scripts generated during the migration and executing in sql under same user and they work. Is there a setting somewhere that may allow these updates to go through? 来源: https://stackoverflow.com/questions/22789395/how-to-enable-codefirst-to-migrate-schema-changes-against-a-replicated

EF 4.3 migrations throwing “Unable to open configSource file”

早过忘川 提交于 2019-12-10 21:49:00
问题 I'm trying to use EF 4.3 migrations feature. My ASP.NET MVC project stores connection strings in external file: <connectionStrings configSource="bin\connections.config" /> All runtime procedures (including automatic migrations) work fine. However, no powershell commandlet, connecting to the database, is able to find external file. It throws "Unable to open configSource file" exception. I was trying to place .config file in different places as well as changing configured external file location

Entity Framework Migration Adding Column Twice

点点圈 提交于 2019-12-10 21:27:09
问题 I'm running Entity Freamework Code First Migrations. When trying to run the application I get the error: A column ID occurred more than once in the specification. I have AutomaticMigrationsEnabled set to true in the configuration because when I run the project, I want the migrations to run automatically. This is the verbose results when I tried running it through the package manager: Applying code-based migration: 201211261626569_AddActiveFlagForProjects. ALTER TABLE [Projects] ADD [Active]

Cannot attach the file ‘{0}' as database '{1}'. Code first. Local SQL EXPRESS Instance. VS 2010 SP1. Windows XP

荒凉一梦 提交于 2019-12-10 20:43:41
问题 I've been using Code First approach. I created a sql express local database "Database.mdf" in Visual Studio 2010 SP1 using MVC 4 template. When I try to run my project at my PC, I get an error: CREATE DATABASE permission denied in database master. Cannot attach the file "...Database.mdf" as database file "Database". What I've tried: deletion my database using SQL SERVER Object explorer(no results, the same error) change connection string (no result, the same error) googled in the Internet.

The string argument 'migrationId' cannot be empty

雨燕双飞 提交于 2019-12-10 20:33:07
问题 Apologies in advance if this has already been answered but I've honestly dug deep and could not find anything relating to this error. In a nutshell, I am unable to make any updates to my database using code first within my ASP.NET Core 1.1.2 project. It's throwing an exception because it's missing an argument which I'm guessing is not to do with PMC. Error message when using 'Update-Database': Text for cross checking Google ;-) System.ArgumentException: The string argument 'migrationId'