ef-migrations

Script EF migration seed from Configuration class

点点圈 提交于 2019-11-30 10:53:54
I have EF migrations working nicely, but I also want to generate the sql script for the seed data from my DbMigrationsConfiguration class. The seed data runs ok when I do Update-Database, but when I do UpdateDatabase -Script I do not get the sql for the seed inserts. I tried -Verbose on a normal Update-Database but I do not see the seed statements output there either. Is this possible? No it is not possible. Configuration class is not part of migration itself - it is infrastructure executing the migration. You have single configuration class for all your migrations and its Seed method is

How to run Code-First Migrations from a psake build?

一曲冷凌霜 提交于 2019-11-30 09:58:12
I can type Update-Database , Enable-Migrations etc, from Package Manager Console and it works fine. If I need to do the same from a regular powershell session, or in a psake build file, then how do I do it? I tried importing the module EntityFramework.5.0.0\tools\EntityFramework.psm1 from the packages directory, and I did get the Update-Database , Enable-Migrations functions, but I cannot supply their arguments - they need a project, source, and 6 more - and there is no documentation whatsoever. Can I not automate the database deploy on some machine in our CI chain ? Keith Hill The problem

Code First Migrations With Existing Table

孤街浪徒 提交于 2019-11-30 09:04:30
In my model I have navigation property Language: public class IntegratorDescription : BaseContract { [Key, Column(TypeName = "bigint"), DataMember] public long Id { get; set; } [DataMember, Column(TypeName = "bigint"), ForeignKey("Language")] public long LangId { get; set; } [DataMember] public string CompanyShortInfo { get; set; } [DataMember, Column(TypeName = "ntext")] public string CompanyInfo { get; set; } public virtual Models.Language Language { get; set; } } Language table already exists and it's done by another ORM, I need to say Migrations not to try to create Language table but

Entity Framework 6: How to override SQL generator?

醉酒当歌 提交于 2019-11-30 08:49:20
I'd like to amend the SQL that's being generated by EF:CF when generating the database schema (DDL), as suggested by the Entity Framework team . How can this be done? I couldn't find anything appropriate via Google. You can override the MigrationSqlGenerator that is used by Entity Framework by calling the DbMigrationsConfiguration.SetSqlGenerator() method in the constructor of your DbMigrationsConfiguration class, passing the database provider name (e.g. "System.Data.SqlClient" for SQL Server), and the MigrationSqlGenerator instance to use for that database provider. Consider the example from

EF5 Code First Migrations: “Column names in each table must be unique” error after using RenameColumn

人走茶凉 提交于 2019-11-30 08:39:10
We're using Entity Framework 5.0 Code First and Automatic Migrations. I had a class like so: public class TraversalZones { public int Low { get; set; } public int High { get; set; } }​ Then we realized these properties weren't really the right names, so we changed them: public class TraversalZones { public int Left { get; set; } public int Top { get; set; } }​ The rename refactored properly throughout the project, but I know Automatic Migrations aren't smart enough to pick up these explicit renames in the IDE, so I first checked to verify the only pending migration was this column rename:

Migration using model first approach in entity framework

浪尽此生 提交于 2019-11-30 08:35:13
I have setup a system where I have taken the model first approach as it made more logical sense for me. Now when even I have some changes in the model currently what I do is - Use the Generate database from model feature of entity framework. I create a dummy database and apply those scripts. which deletes all my data and tables first and then updates the database with the latest sql file which is generated by entity framework. Now I use the Visual Studio's schema compare feature and generate migration scripts for my local database and also for the one which is in production. I go through the

error loading database initializer with EF6

早过忘川 提交于 2019-11-30 08:33:32
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 for details."} The inner exception is ... {"Could not load type 'WeddingPreparations.Dal.WeddingContext'

Unable to run EF5 migration with existing database

牧云@^-^@ 提交于 2019-11-30 08:32:00
问题 First, I've read these questions/answers: EF-migration message How can I stop Add-Migration checking my database has no pending migrations when using Code-Based migrations? Make EF4.3 Code First Migrations ignore pending migrations These all seem to be for EF versions prior to EF5, and my situation doesn't seem to fit these answers. So, let me describe my situation. My application was originally created using EF4, model first. I designed my database with the GUI designer, and used it to

Changing column default values in EF5 Code First

梦想与她 提交于 2019-11-30 08:24:18
问题 I'm trying to use CF to build a model for an existing database. I have a column in which I forgot to set a sane default value. And rather than compromise the purity of the initial migration by changing it, I just figured I'd create another migration (that's what migrations are for, right? :) public override void Up() { AlterColumn("Config", "DefaultTaxPerDollar", c => c.Decimal(nullable: false, precision: 19, scale: 5, defaultValue: 0.087m)); } public override void Down() { AlterColumn(

Many-to-many relationship between entities of same type in MVC3

为君一笑 提交于 2019-11-30 07:42:44
I have an ASP.NET MVC3 application, where I use Entity Framework 4.3 Code-First and Migrations. I've been trying to create a many-to-many relationship between entities of the same type, but when I scaffold the migration with Migrations, it generates a one-to-one relationship. The idea is that one user should be able to follow multiple other users (think Twitter). My User model look something like this: public class User { public int UserId { get; set; } public string Name { get; set; } public DateTime Registered { get; set; } ... public virtual ICollection<User> Follows { get; set; } } When I