ef-migrations

EF5 Code First - Changing A Column Type With Migrations

血红的双手。 提交于 2019-12-17 07:22:28
问题 I am new to EF5 Code First and I'm tinkering with a proof-of-concept before embarking on a project at work. I have initially created a model that looked something like public class Person { public int Id { get; set; } public string FirstName { get; set;} public string Surname {get;set;} public string Location {get;set;} } And I added a few records using a little MVC application I stuck on the top. Now I want to change the Location column to an enum, something like: public class Person {

Debug code-first Entity Framework migration codes

冷暖自知 提交于 2019-12-17 04:41:13
问题 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 回答1: 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

why remove-migration run my app?

末鹿安然 提交于 2019-12-17 04:32:36
问题 I did some version upgrade in last months and now I noticed that when I use "remove-migration" to delete migration that I reverted, it's first run my app. (I noticed that because we do update-database inside startup, so I got to situation where I can't remove migrations, since every time I tried remove migration - it automatically ran the startup which apply the migration to db, then it failed delete it, since it see it in db.) any idea? 回答1: Update for ASP.NET Core 2.1 In ASP.NET Core 2.1

How to delete and recreate from scratch an existing EF Code First database

帅比萌擦擦* 提交于 2019-12-17 02:59:45
问题 I am using EF Code First with EF 5 in VS 2012. I use PM update-database command and I have a simple seed method to fill some tables with sample data. I would like to delete and recreate my x.mdb. The update history seems to be out of sync. If I comment out all my DBSets in my context, update-database runs with no error but leaves some tables in the DB. As I have no valuable data in the DB it seems to the simplest to reset the all thing. How can I accomplish this? 回答1: If I'm understanding it

Multiple DB Contexts in the Same DB and Application in EF 6 and Code First Migrations

久未见 提交于 2019-12-17 02:25:32
问题 I'm new to Entity Framework. I am trying to setup an MVC Application what uses EF 6. I am using Code First Migrations. I am using Areas in the app and would like to have different DbContexts in each area to break it up. I know EF 6 has ContextKey, but I can't find complete information on how to use it. Currently I can only use migrations one context at a time. Can someone give an example with enough detail for a new person to EF like me to understand and use. 回答1: Entity Framework 6 added

An error occurred while getting provider information from the database

南笙酒味 提交于 2019-12-14 03:41:20
问题 Getting the error: System.Data.ProviderIncompatibleException: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct. ---> System.Data.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. ---> System.Data.SqlClient.SqlException: A network-related or instance-specific error

Problems changing PK datatype using EntityFramework CodeFirst migrations on Azure

白昼怎懂夜的黑 提交于 2019-12-14 02:32:40
问题 I have a code-first EntityFramework project hosted on Azure. Currently I handle migrations by Run Add-Migration from Package Manager Console Run Update-Database -script from Package Manager Console getting me an .sql script Manually run the script on Azure after testing on my dev environment This has been working pretty smoothly so far. But I am running into some serious issues trying to change a primary key of one of my tables from an int to a long. Here is the migration script that got

EF Core Migrations manual edits possible?

∥☆過路亽.° 提交于 2019-12-13 16:51:01
问题 I am using EF Core 2.0 in my sample project with some value object configurations. I modify the code and generate migrations via CLI command line. In the last migration rather than adding a new database table as it should, it is trying to rename existing tables to each other and create an extra table for existing one. I could not figure out the reason for it. Issue is, since with EF Core the snapshot is a separate auto-generated file from the migration itself I don't want to modify the

What is Entity Frameworks mechanism to prevent multiple executions of the same migration?

和自甴很熟 提交于 2019-12-13 16:15:36
问题 Of course EF is storing the latest migration to the MigrationHistory table to determine if a specific migration was already executed. My question is about what EF is doing to prevent multiple executions of the same migration at the same time. Assuming you have two applications which runs under different application domains using the same database. Both apps are starting simultaneously, wherefore both starts to migrate to the latest database migrations. Assume MigrateDatabaseToLatestVersion is

Entity Framework 4.3: 'update-database' when configuration files are separated

馋奶兔 提交于 2019-12-13 13:45:17
问题 Moved to ef 4.3 with AutomaticMigrationsEnabled = true; In web.config have the following settings: <appSettings configSource="appSettings.config" /> <connectionStrings configSource="connectionStrings.config" /> In Package Manager Console execute update-database -verbose and got the following error: System.Configuration.ConfigurationErrorsException: Unable to open configSource file 'connectionStrings.config' The error is understandable: it tries to open connectionStrings.config file from the