ef-migrations

EF backward compatible DB migrations

独自空忆成欢 提交于 2019-12-10 13:56:03
问题 I'm trying to figure out how to implement the following deployment scenario using EF code-first and migrations. The idea is that I would like to upgrade the DB with backward compatible schema changes (e.g.: add a column) and test that everything still works. It is inspired by green/blue deployment but it's not entirely following that pattern. The reasoning behind this is in following this process: Upgrade database (EF migration) Test website Update website code If something goes wrong, revert

The navigation property 'SenderId' is not a declared property on type 'Conversation'

时光总嘲笑我的痴心妄想 提交于 2019-12-10 13:47:02
问题 When I try to do Update-Database, I get this error: The navigation property 'SenderId' is not a declared property on type 'Conversation'. Verify that it has not been explicitly excluded from the model and that it is a valid navigation property. Edit I believe problem is in mapping relations between Conversation and User, because Conversation and User are connected with two one to many relationships i.e. Conversation has two foreign keys pointing to User Here is how User and Conversation are

The term 'Enable-Migrations' is not recognized as the name of a cmdlet, function, script file, or operable program

好久不见. 提交于 2019-12-10 13:22:31
问题 When I enter this command: 'Enable-Migrations' in Package Manager Console I get this error: "The term 'Enable-Migrations' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a p ath was included, verify that the path is correct and try again. At line:1 char:18 + Enable-Migrations <<<< + CategoryInfo : ObjectNotFound: (Enable-Migrations:String) [], CommandNotFoundException + FullyQualifiedErrorId :

EF Add-Migration indicates “No pending explicit migrations” but Update-Database complains “..there are pending changes”

丶灬走出姿态 提交于 2019-12-10 13:15:45
问题 I frequently encounter the following situation with Entity Framework code first migrations. I add some migrations and update the database with them successfully. When later I wish to add a new migration, the Add-Migration command complains that its "Unable to generate an explicit migration because the following explicit migrations are pending...". I.e., it seems to forget that its already applied those migrations previously and therefore they shouldn't be now considered as pending. If I try

The model backing the 'DataContext' context has changed since the database was created

依然范特西╮ 提交于 2019-12-10 12:37:56
问题 I am trying to use Code First with Migrations. Even though there are no current changes to my model, I'm getting an exception. When I add a migration, the up and down are empty, but I get a runtime error with the message as follows: An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code Additional information: The model backing the 'MyDataContext' context has changed since the database was created. Consider using Code First

Entity Framework 7 Migration Scaffolding in Class Library with Configuration

泪湿孤枕 提交于 2019-12-10 12:36:30
问题 Trying to add migrations to an EF7 Model that lives in an ASP.NET 5 class library. When running dnx . ef migration add mymigration fails with different results depending on which project I run it on. If I run it in the folder of the main project, it cannot locate a DbContext , this makes sense because the DbContext is in the shared project and ef commands likely don't care about dependencies. If I run it in the folder of the shared project, it does not have access to the connection string

Entity Framework Code First override onModelCreating() for TPT Inheritance Screwing Up Identity User and Role Models [duplicate]

时光毁灭记忆、已成空白 提交于 2019-12-10 11:37:48
问题 This question already has an answer here : The entity type 'Microsoft.AspNet.Identity.EntityFramework.IdentityUserLogin<string>' requires a key to be defined (1 answer) Closed 11 months ago . I'm having problems extending the Fluent API to my inheritance classes. I have taken the TPT (table per type) method and each type of the inheritance has a table. I like table per type because the database is fully normalized and easy to maintain. I am getting an error with overiding the onModelCreating

Code First migrations updating the wrong Db on localdb

旧巷老猫 提交于 2019-12-10 11:17:30
问题 I am using code first migrations to create and update the database for my asp mvc site. I have a DbContext, which is in another project in the solution. public class EFDbContext : DbContext { public DbSet<Book> Books { get; set; } public DbSet<Author> Authors { get; set; } public DbSet<Publisher> Publishers { get; set; } } When i enable-migrations and add-migration [name] . It seems to create its own db called [foo-projectname].Domain.Concrete.EFDbContext Instead of the attaching to the

How to create and use a generic class EntityTypeConfiguration<TEntity>

随声附和 提交于 2019-12-10 10:36:35
问题 Code I have two very simple interfaces in my application Represents entities that are saved in the database public interface IEntity { int Id { get; set; } } Entities that have only the Nome field as required field to save the entity public interface IEntityName : IEntity { string Nome { get; set; } } And many classes implementing this interface public class Modalidade : IEntityName { public int Id { get; set; } public string Nome { get; set; } } public class Nacionalidade : IEntityName {

Entity Framework Code First Migration Class File

瘦欲@ 提交于 2019-12-10 10:27:08
问题 I'm building an application using ASP.NET MVC 4 with Entity Framework 5.0. I've recently learned about EF Code-First Migrations tool you can implement on your application for your database. I ran "Enable-Migration" in the PM Console, and it enabled successfully and created the "InitialCreate.cs" class as expected with the appropriate up() and down() methods filled in with the table creations. Then I went ahead and added another class (Category.cs) with 2 simple properties (id, name) and