ef-migrations

EF (Entity Framework) 4.3 Migration tool does not work on EF 4.1 DB

无人久伴 提交于 2019-11-27 16:45:34
问题 I want to modify one DB which was developed with EF 4.1 (Code First). I upgraded the project into EF 4.3 and follow this steps: http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx Everything is going well, but when I want to test on current DB (EF 4.1 Code First), Update-Database raise this error: Cannot scaffold the next migration because the target database was created with a version of Code First earlier than EF 4.3 and does not contain the

Automatically execute migrations when publishing ASP.NET Core app

跟風遠走 提交于 2019-11-27 16:39:57
问题 Question Is there any ways that I can automatically execute the migration code (EF 7) when publishing my ASP 5 application to IIS using Web Deploy? I Tried in the project.json , I added this code in the scripts : "scripts" : { "prepublish": ["dnx ef database update", "other commands..."], "postpublish": ["dnx ef database update"] } none worked for me. Additional Info I followed the instructions on this link to deploy my ASP 5 RC-1 web application to IIS using web deploy. After doing so in the

EF Code First DbMigration without nuget

核能气质少年 提交于 2019-11-27 16:13:10
问题 How to migrate DB without nuget? It is not possible to use Visual Studio with nuget in production environment. Currently, many examples only teach us to use Visual Studio with nuget. How to use the generated DbMigration classes? 回答1: The easiest way is: Database.SetInitializer( new MigrateDatabaseToLatestVersion<MyDbContext, MyDbMigrationsConfiguration>()); This will run the migrations when initializing the DbContext. You can also force the execution manually: var migrator = new DbMigrator

“Execute Code First Migrations” checkbox disappeared from my publish profile

ぃ、小莉子 提交于 2019-11-27 16:07:37
问题 I'm using web deploy to deploy an MVC4 application using EF5 code first. I made a publish profile called "development" that uses web deploy for application and database using the 'Execute Code First Migrations' checkbox to run migrations on application startup. The publishing worked great for a while. At some point I added a new publish profile called "test" to deploy to another server, which uses the ftp method of deploy and no automatic migrations. This works fine too. However, when I tried

Cannot enable migrations for Entity Framework in class library

狂风中的少年 提交于 2019-11-27 15:27:47
问题 I just got on board with EF 5 and am using their code-first migrations tool but I seem to get an error when I try to enable migrations. I type Enable-Migrations into the package manager console and then it says No classes deriving from DbContext found in the current project. Edit the generated Configuration class to specify the context to enable migrations for. Code First Migrations enabled for project MyApp.MvcUI. It then creates a Migrations folder and a Configuration class in my MvcUI

Value cannot be null. Parameter name: entitySet

有些话、适合烂在心里 提交于 2019-11-27 14:58:21
I have a fairly standard setup with simply POCO classes public class Project { public int ProjectId { get; set; } public string Name { get; set; } public int? ClientId { get; set; } public virtual Client Clients { get; set; } } They use an interface public interface IProjectRepository { IEnumerable<Project> Projects { get; } } and are constructed as a repository for ninject to bind to public class EFProjectRepository : IProjectRepository { private EFDbContext context = new EFDbContext(); public IEnumerable<Project> Projects { get { return context.Projects; } } } The actual context is a simply

Seed Entities AND Users, Roles?

拟墨画扇 提交于 2019-11-27 14:09:16
How do you seed users, roles and app specific entities? It appears as though the IdentityModel targets its own Context? internal sealed class Configuration : DbMigrationsConfiguration<Project.Models.SchoolContext> { public Configuration() { AutomaticMigrationsEnabled = false; } protected override void Seed(Project.Models.SchoolContext context) { // Seed the Entities // context.People.AddOrUpdate( // p => p.FullName, // new Person { FullName = "Andrew Peters" } // ); // } } vs. protected override void Seed(Project.Models.ApplicationDbContext context) { if (!context.Roles.Any(r => r.Name ==

How to set the isolation level for Entity Framework CodeFirst Migrations

谁说胖子不能爱 提交于 2019-11-27 13:48:41
问题 If you run an entity framework migration (either automatic or explicit) against tables published for SQL Server replication you get the following error: You can only specify the READPAST lock in the READ COMMITTED or REPEATABLE READ isolation levels There have been questions about this before (here), but they completely fail to address the underlying cause: Entity Framework migration is run at the Serializable isolation level (as clearly shown in the SQL Server profiler). Which is a safe

Change data in migration Up method - Entity Framework

▼魔方 西西 提交于 2019-11-27 12:55:29
问题 I have added a new property into my existing model. It's a bool property with default value true. There are existing data in this table and I would like to set one specific row's new property to false right after creating the new field, in the Up method. public override void Up() { AddColumn("dbo.RequestValidationErrors", "IsBreaking", c => c.Boolean(nullable: false)); using (Context ctx = new Context()) { var validation = ctx.RequestValidationErrorSet.FirstOrDefault(x => x.WordCode ==

AutomaticMigrationsEnabled false or true?

拟墨画扇 提交于 2019-11-27 12:39:01
In EF projects, Is there any best practice for setting AutomaticMigrationsEnabled ? More declaration: In our team after modifying a model we usually run "add-migration" and "update-databse" commands in Package Manager Console. This error raises when other developers run the project: "Can not drop database because it is in use" Every time this happen the first modifier should Check In whole project and others have to GET modified objects. In many cases we don't want to check in the already created model and migration! This situation is annoying,are there any solution for this kind of problems.