ef-migrations

How to seed data using EntityFramework Code first Migrations

可紊 提交于 2019-11-30 17:14:48
Hi I'm using the Beta 1 version of this nuGet package, the database is allready created and I need to know if there is a way to populate my tables through migrations. Thanxs The intro post shows how to seed data http://blogs.msdn.com/b/adonet/archive/2011/11/29/code-first-migrations-beta-1-no-magic-walkthrough.aspx Seed data: Override the Seed method in this class to add seed data. - The Seed method will be called after migrating to the latest version. - You can use the DbContext.AddOrUpdate() helper extension method to avoid creating duplicate seed data. E.g. myContext.AddOrUpdate(c => c

How to migrate database schema from Identity 2.2.0 to 3.0.0-rc1-final

血红的双手。 提交于 2019-11-30 14:47:51
I've been playing around migrating an existing application running on MVC5 with ASP.NET Identity 2.2.0 having trouble finding proper information, i'd like to ask how you are supposed to do this migration? I've used a couple of hours on this problem and have found a solution that allows me to log in with Identity 3.0.0-rc1-final with ef7 on my old but migrated database. I will post what I did as an answer, but i'd very much like inspiration or other ways to have done it. First I generated a new migration with the following command dnx ef migration add MigrateIdentityFrameworkFrom2to3 This

enable-migrations in x64 Project gets System.BadImageFormatException

帅比萌擦擦* 提交于 2019-11-30 14:32:47
问题 I have a project set to x64 (it's using some Nuget packages that are 64-bit only). Everything runs and deploys fine, but trying to run EF's enable-migrations at the Package Manager Console gets me a System.BadImageFormatException . The full exception: PM> enable-migrations System.BadImageFormatException: Could not load file or assembly or one of its dependencies. An attempt was made to load a program with an incorrect format. File name: at System.Reflection.RuntimeAssembly._nLoad(AssemblyName

Multiple DbContexts on one DB with Code First Migrations

你。 提交于 2019-11-30 14:29:36
问题 I stumbled uppon the same problem as described in this question. In addition, i didn't want to loose the __migrationHistory table from the database. I tried it with the suggested Solution of using one "super" context which contains all DbSet<>s and using the normal Contexts, but i got a error. ("Model backing DbContext has been changed") This is easily avoidable if you just kill the __migrationHistory table from the SQL server, but as i said, i want to keep the history. I found a simple and

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

半腔热情 提交于 2019-11-30 14:14:24
问题 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

EF6 Code First - may cause cycles or multiple cascade paths

╄→尐↘猪︶ㄣ 提交于 2019-11-30 14:06:58
I'm using EF6 Code First. I have two classes: public class Player { [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] [Key] public int Id { get; set; } [Required, MinLength(2, ErrorMessage = "Player name must be at least 2 characters length")] public string Name { get; set; } [Required] public int TeamClubId { get; set; } [Required] public int TeamNationalId { get; set; } [Required, ForeignKey("TeamClubId")] public virtual Team Club { get; set; } [Required, ForeignKey("TeamNationalId")] public virtual Team National { get; set; } } And: public class Team { [DatabaseGenerated

Migration using model first approach in entity framework

岁酱吖の 提交于 2019-11-30 13:49:48
问题 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

EF CodeFirst: Either the parameter @objname is ambiguous or the claimed @objtype (COLUMN) is wrong

╄→尐↘猪︶ㄣ 提交于 2019-11-30 12:23:57
问题 I've a table named EducationTypes and an Entity named EducationType , I renamed one of entity properties, now I'm frequently getting Either the parameter @objname is ambiguous or the claimed @objtype (COLUMN) is wrong . How can I solve this issue? The generated SQL Script: EXECUTE sp_rename @objname = N'dbo.EducationTypes.nvarchar', @newname = N'EducationTypeTitle', @objtype = N'COLUMN' 回答1: If you're using Code First and have (an) existing Migration script(s) and are trying to overwrite a

Why does Entity Framework's EF Migrations Add-Migration step require a database connection string?

ぃ、小莉子 提交于 2019-11-30 11:54:03
问题 I am trying to use and understand EF Migrations (using EF 4.3.1, Code First). In order to scaffold a new change, I have to use a command like this: Add-Migration MyMigration -ConnectionString "Data Source=.;Initial Catalog=mydb;" -ConnectionProviderName "System.Data.SqlClient" -StartUpProjectName MyWebsite -ProjectName MyEF.Migrations Why does Add-Migration require connection string data? Update-Database needs one, that makes sense. But doesn't Add-Migration have everything it needs from the

Enabling Code First Entity Framework VS Web Express 2012

巧了我就是萌 提交于 2019-11-30 11:44:43
I am trying to enable Code First in my Visual Studio Web Express 2012. From what I have read so far I have to use the Package Manager Console and the command Enable-Migrations. When I do this I get the following error. Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///E:\Working\wingtoysdl\C#\packages\EntityFramework.5 .0.0\tools\EntityFramework.PowerShell.Utility.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)" At E:\Working\wingtoysdl\C#\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:398