ef-migrations

Entity Framework creates empty migration but insists that my model is different

主宰稳场 提交于 2019-12-30 08:36:23
问题 Today is a sad day. First thing today I saw EF exception saying that " The model backing the 'DomainContext' context has changed since the database was created. ". It is close to midnight and I still see this error. This is the end of my career -( I'm pretty sure nothing has changed in the model, yet the error appeared. I have tried creating a new migration, it came out empty: public void Up() { } public void Down() { } Applying this migration did not do any good - the error persisted. I've

Entity Framework Migrations can't drop table because of foreign key constraint

牧云@^-^@ 提交于 2019-12-30 05:45:35
问题 I have reverse-engineered the existing database to the code-first model. Some tables are to be kept but most are to be removed and completely re-architected for the new version. I delete some old classes and their mapping and add-migration. The migration looks like this: public override void Up() { DropForeignKey("dbo.Bingo_Review", "BingoID", "dbo.Bingo"); DropForeignKey("dbo.Bingo_Review_Text", "BingoReviewID", "dbo.Bingo_Review"); DropForeignKey("dbo.Bingo_Bonus", "BingoID", "dbo.Bingo");

How to switch between DatabaseGeneratedOption.Identity, Computed and None at runtime without having to generate empty DbMigrations

自闭症网瘾萝莉.ら 提交于 2019-12-30 04:40:12
问题 I am migrating a legacy database to a new database which we need to access and "manage" (as oxymoronic as it might sound) primarily through Entity Framework Code-First. We are using MS SQL Server 2014. The legacy database contained some tables with computed columns. Typical GUID and DateTime stuff. Technically speaking, these columns did not have a computed column specification, but rather where given a default value with NEWID() and GETDATE() We all know that it is very easy to configure the

How do I create the asp.net Identity tables manually with migrations?

巧了我就是萌 提交于 2019-12-30 02:27:06
问题 I would like the asp.net Identity tables to exist in my database, and as well, have the corresponding respective code-first models generated before I actually run the mvc app and create a user, so that I may code some logic against these classes before hand. Is there a way that I can create these tables/classes with migrations manually? 回答1: If you want to add it manually in your database, you'll have to write it in a Structured Query Language ;) CREATE TABLE [dbo].[__MigrationHistory] (

What causes a TypeLoadException on Migrate.exe for EF6?

不羁的心 提交于 2019-12-29 07:53:14
问题 I'm trying to run EF's migrate.exe from the command line as part of our build process. This is my actual command: migrate.exe Hydrogen.Data.dll /startupConfigurationFile:..\..\..\Hydrogen.Web\Web.config /verbose And it continually throws this exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System

How to uninstall EF Core tables? Or how to remove all migrations ? Or how to call `dotnet ef database update 0` from user code?

别说谁变了你拦得住时间么 提交于 2019-12-29 01:51:30
问题 I'm developing web app and near it small command line application that install ef core tables in the DB. Last can be done calling dbContext.Database.Migrate(); and this works. Now I want to provide unistall option (with this app). But how to remove migrations (means call functionality of dotnet ef database update 0 from my code) ? It could be not one command call (as it was in case with dbContext.Database.Migrate(); ). But snippet with loop through all migrations in migrations assembly and

Triggering EF migration at application startup by code

こ雲淡風輕ζ 提交于 2019-12-28 18:07:08
问题 Using Entity Framework Migrations (Beta1), using Update-Database command is all good during development. But when the application is running on some customer's server somewhere, I really want my application to automatically update it's database schema to the latest version when it's started. Is this possible? Documentation is scarce. 回答1: They aren't providing a way to do this until RTM, at which point they have promised a command line app and a msdeploy provider. Source: http://blogs.msdn

Foreign Key To Microsoft.AspNet.Identity.EntityFramework.IdentityUser?

好久不见. 提交于 2019-12-28 16:05:43
问题 I'm in VS 2013 and have just created an MVC application. I'm creating an object I intend to have a foreign key to the AspNetUsers table in the resulting database. The project does have an ApplicationUser (deriving from IdentityUser) that looks like a property-column match with the AspNetUsers table. How do we properly declare a foreign key to this? public MyObject { public string UserId { get; set; } [ForeignKey("UserId")] public ApplicationUser User { get; set;} // other properties } Now, I

Automatic Migrations for ASP.NET SimpleMembershipProvider

我们两清 提交于 2019-12-28 03:18:10
问题 So I tried to use automatic migrations with my new MVC 4 Project but somehow it isn't working. I followed this blog post step by step. I've added the changes to the UserProfile account model (the NotaryCode field): [Table("UserProfile")] public class UserProfile { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int UserId { get; set; } public string UserName { get; set; } public int NotaryCode { get; set; } } Then I wrote on the package manager console enable

Oracle.ManagedDataAccess.EntityFramework - ORA-01918: user 'dbo' does not exist

不问归期 提交于 2019-12-28 03:05:25
问题 I am trying to implemente code First Migrations with Oracle.ManagedDataAccess 6.121.1.0 provider, but with no success at all. As I am receiving a ORA-code, I am assuming that the connection are been opened successfully. But the Migrations are failing because, maybe, the provider are behaving as a SQL Server, instead of Oracle. I think that beacause it is traying to use 'dbo' as default schema. Here is my web.config settings: <configuration> <configSections> <section name="entityFramework"