ef-migrations

Adding 'GO' statements to Entity Framework migrations

人走茶凉 提交于 2019-11-27 08:54:45
So I have an application with a ton of migrations made by Entity framework. We want to get a script for all the migrations at once and using the -Script tag does work fine. However...it does not add GO statements in the SQL giving us problems like Alter view should be the first statement in a batch file... I have been searching around and manually adding Sql("GO"); help with this problem but only for the entire script. When I use the package console manager again it returns an exception. System.Data.SqlClient.SqlException (0x80131904): Could not find stored procedure 'GO'. Is there a way to

Cant remove identity attribute from PK

大城市里の小女人 提交于 2019-11-27 08:27:54
问题 I need to change the data type of the primary key on one of my tables to string from int (I didn't say I WANT to...). The migration generates this bit of code: AlterColumn("dbo.Venues", "ID", c => c.String(nullable: false, maxLength: 128)); This causes SQL server to complain that the data type must be int, bigint, etc because the column is an identity column. I added the following but it appears to have no effect: AlterColumn("dbo.Venues", "ID", c => c.Int(identity:false)); Question: How do I

How to disable migration in Entity Framework 4.3.1?

▼魔方 西西 提交于 2019-11-27 08:13:13
Is there any way to disable migration in Entity Framework 4.3.1? I removed the migrations folder from the project and the generated tables in my database, but it doesn't work! How can you remove the migration? Ladislav Mrnka If you don't want to use migrations but in the same time you want EF to create database for you, you just need to set correct database initializer: Database.SetInitializer<YourContextType>(new CreateDatabaseIfNotExists<YourContentType>()); Noel Deleting the Migrations folder has worked for me. I don't get any errors, it puts me back to where I started. Buzzrick The way

Entity framework 4.3 run migrations at application start

限于喜欢 提交于 2019-11-27 07:34:45
What is the best way to execute all required db migrations at application start with EF 4.3? The best way should be using new MigrateDatabaseToLatestVersion initializer. Database.SetInitializer<YourContext>( new MigrateDatabaseToLatestVersion<YourContext, YourMigrationsConfig>()); Database.Initialize(false); A great description of the EF 4.3 configuration options can be found at EF 4.3 Configuration File Settings on the ADO.NET team blog. The very last section describes Database Initializers, including the new Code First MigrateDatabaseToLatestVersion initializer. Although Entity Framework

How to initializing the code-first Entity Framework database in an Azure Mobile Services project

試著忘記壹切 提交于 2019-11-27 07:13:38
问题 I am utterly confused by the use of Entity Frameworks code-first migrations within Azure Mobile Services. I'm following the article How to make data model changes to a .NET backend mobile service with additional help from Stack Overflow answers, and have also read Code First Migrations and Code First Migrations in Team Environments and watched Migrations - Under the Hood. In Visual Studio 2015 I make a new Azure Mobile Service, and then enable code-first migrations by going to the nuget

Sequence contains more than one element error in EF CF Migrations

佐手、 提交于 2019-11-27 06:49:57
问题 I created some models, added the migration and then did an update database operation, though at my last update database operation I got the error message saying: Sequence contains more than one element Below you can find my migration configuration: context.Categories.AddOrUpdate(p => p.CategoryName, new Category { CategoryName = "Sport" }, new Category { CategoryName = "Music" } ); context.Subcategories.AddOrUpdate(p => p.SubcategoryName, new Subcategory { SubcategoryName = "Football" }, new

How can I disable migration in Entity Framework 6.0

谁都会走 提交于 2019-11-27 06:47:19
I'm trying to ignore the "Automatic" migration using Entity Framework 6.0 rc1. My problem is that I don't want this feature right now and every time that my application runs I can see all entity logs trying to create all tables. Anticipate thanks. Try this: internal sealed class Configuration : DbMigrationsConfiguration<YourContext> { public Configuration() { AutomaticMigrationsEnabled = false; } } UPDATE: You can also try this: Database.SetInitializer<YourContextType>(new CreateDatabaseIfNotExists()); Carlos Teixeira You can put this inside your entityFramework section of the app.config:

EF 4.3 Auto-Migrations with multiple DbContexts in one database

こ雲淡風輕ζ 提交于 2019-11-27 06:45:53
I'm trying to use EF 4.3 migrations with multiple code-first DbContexts. My application is separated into several plugins, which possibly have their own DbContext regarding their domain. The application should use one single sql-database. When I try to auto migrate the contexts in an empty database, this is only successful for the first context. Every other context needs the AutomaticMigrationDataLossAllowed-Property set to true but then tries to drop the tables of the previous one. So my question is: How can I tell the migration-configuration just to look after the tables defined in their

Migrations in Entity Framework in a collaborative environment

大城市里の小女人 提交于 2019-11-27 06:37:17
We have multiple developers working on a project that uses Entity Framework 5.0. Every developer uses his own local SQL 2012 database so he can develop and test without impeding others. At first, we used a hybrid of automatic migrations and code-based migrations. That didn't work well at all so we decided to disable automatic migrations and to only allow code-based. I should add that we started again with a clean database without a 'corrupted' _MigrationsHistory from all the automatic migrations. So now the workflow is: Developer changes his datamodel Does add-migration <Name> and applies it

Entity Framework Code First Using Guid as Identity with another Identity Column

放肆的年华 提交于 2019-11-27 06:25:18
a.k.a How can we create multiple identity columns in Code First? Because of clustering performance, a common recommendation is to use an autoincremented integer column instead of a GUID created with newid() . In order to declare a column as autoincrement, you have to specify it with the Annotation [DatabaseGenerated(DatabaseGeneratedOption.Identity)] . But, you can only have one identity in a table. So starting with a base model like: public abstract class ModelBase { // the primary key public virtual Guid Id { get; set; } // a unique autoincrementing key public virtual int ClusterId { get;