ef-migrations

EF migration for changing data type of columns

本小妞迷上赌 提交于 2019-11-27 00:50:22
I have a Model in my project as below: public class Model { public int Id { get; set; } public long FromNo { get; set; } public long ToNo { get; set; } public string Content { get; set; } public long TicketNo { get; set; } } The migration is as below public override void Down() { AlterColumn("dbo.Received", "FromNo", c => c.Long(nullable: false)); AlterColumn("dbo.Received", "ToNo", c => c.Long(nullable: false)); AlterColumn("dbo.Received", "TicketNo", c => c.Long(nullable: false)); } public override void Up() { AlterColumn("dbo.Received", "FromNo", c => c.String()); AlterColumn("dbo.Received"

Is it OK to update a production database with EF migrations?

雨燕双飞 提交于 2019-11-27 00:00:54
问题 According to this blog post most companies using EF Migrations are supposedly not updating the database schema of production databases with EF migrations. Instead the blog post's author recommends to use Schema update scripts as part of the deployment process. I've used Schema update scripts for a few years now and while they work, I was planning to use EF migrations instead in the future for the following reasons: Faster deployment, less downtime A simpler deployment procedure Much easier

There is already an object named in the database

泄露秘密 提交于 2019-11-26 23:42:18
Update-Database failed from Package Manager Console. I've used Entity Framework 6.x and code-first approach. Error is "There is already an object named 'AboutUs' in the database." How can I solve this problem? internal sealed class Configuration : DbMigrationsConfiguration<Jahan.Blog.Web.Mvc.Models.JahanBlogDbContext> { public Configuration() { AutomaticMigrationsEnabled = true; AutomaticMigrationDataLossAllowed = false; } protected override void Seed(Jahan.Blog.Web.Mvc.Models.JahanBlogDbContext context) { } } My DbContext is: public class JahanBlogDbContext : IdentityDbContext<User, Role, int

Mapping Database Views to EF 5.0 Code First w/Migrations

不问归期 提交于 2019-11-26 22:55:02
I'm trying to map a SQL View to an entity in EF 5.0 Code First w/Migrations for displaying some basic information on a page without having to query multiple tables for that information (which currently takes ~20 seconds to load. NOT GOOD. ). I've heard that it is possible to do, but I haven't been able to figure out or find online a way to properly do so. EDIT: For a more in-depth look at my solution to this problem, read this blog post on the subject. Here is my View: CREATE VIEW [dbo].[ClientStatistics] AS SELECT ROW_NUMBER() OVER (Order By c.ID) as Row, c.LegacyID, c.ID, c.ClientName, slc

GUID COMB strategy in EF

回眸只為那壹抹淺笑 提交于 2019-11-26 22:46:57
Is there any way to implement the Guid COMB identity strategy for objects in the new Entity Framework 4.1 using the CodeFirst design? I thought setting the StoreGeneratedPattern would work, but it still gives me normal GUIDs. I guess you are using SQL server as your database. This is nice example of inconsistency among different MS tools. SQL server team doesn't recommend using newid() as default value for UNIQUEIDENTIFIER columns and ADO.NET team use it if you specify Guid property as autogenerated in the database. They should use newsequentialid() instead! If you want sequential Guids

Possible to default DateTime field to GETDATE() with Entity Framework Migrations?

时间秒杀一切 提交于 2019-11-26 22:21:26
I added EntityFramework.Migrations (Beta 1) to an existing Code-First app that is going through some changes (for both migration capabilities and more fine-tuning of the tables I am generating from my code-first API) and ran into the GETDATE() scenario. I was already using a custom initializer class in my DbContext to run SQL scripts to set some fields and create indexes in my database. A handful of my AlterTable scripts are primary just to setup fields with default values(such as certain DateTime fields being set to GETDATE()). I was really hoping EntityFramework.Migrations would have an

MVC 5 Seed Users and Roles

◇◆丶佛笑我妖孽 提交于 2019-11-26 21:22:26
I have been playing about with the new MVC 5, I have a few models, controller and views setup using code first migrations. My question is how do I seed users and roles? I currently seed some reference data in my Seed method in Configuration.cs. But it looks to me that the user and roles tables are not created until something first hits the AccountController. I currently have two connection strings so I can separate my data from my authentication into different databases. How can I get the user, roles, etc tables populate along with my others? And not when the account controller is hit? Valin

Entity Framework Migrations: Including Go statement only in -Script output

两盒软妹~` 提交于 2019-11-26 20:56:07
问题 As part of planning an Entity Framework migration, in order to debug data movement, I would often use the -Script parameter to generate the script. I could then take this script to Query Analyzer and wrap it in a transaction in order to test it manually. I came across a situation where we needed a Go statement to execute the script properly. The following code was added to the migration in order to output a Go in the proper place. Sql("GO"); This adds a GO statement in the proper position

Debug code-first Entity Framework migration codes

て烟熏妆下的殇ゞ 提交于 2019-11-26 19:27:20
I'm using Entity Framework code first in my website and I'm just wondering if there is any way to debug the migration codes. You know, like setting breakpoints and stuff like this. I'm using Package Manager Console to update the database using Update-Database . Thanks m_david I know that EF Code First Migrations is relatively new tool but don't forget about you are still in .NET. So you can use: if (System.Diagnostics.Debugger.IsAttached == false) { System.Diagnostics.Debugger.Launch(); } After that you can see your InnerException. Or you can use try...catch statement like this: Exception

EF 5 Enable-Migrations : No context type was found in the assembly

十年热恋 提交于 2019-11-26 19:11:05
问题 I have 4 projects : Toombu.Entities : all models are there Toombu.DataAccess: Mapping, Repository and ToombuContext Toombu.Logique : Logic of my application Toombu.Web : MVC 4 application. With all others DLL. I tried to enable migration in Toombu.Web but i had this error : No context type was found in the assembly How can I enable migration ? 回答1: use -ProjectName option in Package Manager Console: Enable-Migrations -ProjectName Toombu.DataAccess -StartUpProjectName Toombu.Web -Verbose 回答2: