ef-migrations

What files am I missing wile running migrations from a console app?

别来无恙 提交于 2019-12-06 21:45:34
With Entity Framework 6 and a working PostgreSQL database plus connection I am trying to run the Add-Migration and Update-Database commands and create an update script via a console app. It is possible to run the commands from a console since it are "just thin wrapper around an API", see this SO-answer for the example I used. The creation of migrations work, three regular files are created, namely: Initial.cs Initial.Designer.cs Initial.resx Here's the console app that does not work for Update-Database . public static void Main() { // Specify the name of the database migration // Note: make

Move property to new Entity in Entity Framework Code First Migration

随声附和 提交于 2019-12-06 21:19:26
I'm using Entity Framework Code First approach in my project. I have a problem with database migration. Now I have the entity public class Event { public int Id { get; set; } public string Title { get; set; } public string City { get; set; } } I have already have data in my existing DataBase. Now I want to extend City property, like this public class Event { public int Id { get; set; } public string Title { get; set; } public virtual Location Location { get; set; } } so, City become to Location with many properties. public partial class Location { public int Id { get; set; } public string

How to UPDATE DATABASE in Code First approach automatically after check-in and Publish code in Continuous deployment

耗尽温柔 提交于 2019-12-06 21:04:39
​In our Web API application, Continuous deployment need a following scenario. User will check in code in VS, Code will get automatically build, Code will be Published, Code will be deployed. But If we are using Entity Framework Code First approach, How can we update database without manual commands (Add-Migration/Update Database)and make database up to date with that check-in. You can try to run Add-Migration/Update Database commands in the build/deploy process. Assume you are using vNext build, Add a " Nuget Installer " task in your build definition first to restore the Entity Framework

EF code first migration error “Object has been disconnected or does not exist at the server”

橙三吉。 提交于 2019-12-06 20:13:00
问题 I am using Entity Framework 6.1.1 on SQL Server 2008 and I have a long running code first migration (about 20 minutes). It gets to the end and then gives the following error. System.Runtime.Remoting.RemotingException: Object '/f10901d8_94fe_4db4_bb9d_51cd19292b01/bq6vk4vkuz5tkri2x8nwhsln_106.rem' has been disconnected or does not exist at the server. at System.Data.Entity.Migrations.Design.ToolingFacade.ToolLogger.Verbose(String sql) at System.Data.Entity.Migrations.Infrastructure

How to Change the name of a primary key in EF Code First?

梦想的初衷 提交于 2019-12-06 19:06:26
问题 I have a scenario where i would like to change the primary key name in an entity and be able to run update-database -force. See below for code and error getting when i try. Entity was: public class Team { [Key] [HiddenInput(DisplayValue = false)] public virtual int Id { get; set; } [Display(Name = "Full Name:")] public virtual string Name { get; set; } } Entity Changed to: public class Team { [Key] [HiddenInput(DisplayValue = false)] public virtual int TeamId { get; set; } [Display(Name =

Error when running Update-Database with EF 4.3

倾然丶 夕夏残阳落幕 提交于 2019-12-06 13:56:15
I upgraded a project to Entity Framework 4.3 and enabled migrations on the project. However, I get this error when running the Update-Database command: Cannot scaffold the next migration because the target database was created with a version of Code First earlier than EF 4.3 and does not contain the migrations history table. To start using migrations against this database, ensure the current model is compatible with the target database and execute the migrations Update process. (In Visual Studio you can use the Update-Database command from Package Manager Console to execute the migrations

Set identity to the previous created column during migration

风格不统一 提交于 2019-12-06 12:27:40
I have a project with the CodeFirst database (Entity Framework 6) and two migration steps. Database is updated automatically by using this code in Application_Start in Global.asax: Database.SetInitializer( new MigrateDatabaseToLatestVersion<MyDBEntities, MyNamespace.Configuration>()); First migration step is creating the tables: CreateTable( "dbo.GalleryAlbum", c => new { Id = c.Int(nullable: false), //other columns..... }) .PrimaryKey(t => t.Id); CreateTable( "dbo.GalleryPics", c => new { Id = c.Int(nullable: false), //other columns..... }) .PrimaryKey(t => t.Id) .ForeignKey("dbo.GalleryAlbum

Entity Framework migrator's connection

柔情痞子 提交于 2019-12-06 11:15:14
Using the Entity Framework 5.0, I am attempting to manually migrate my code-first database during my MVC site's start up routine. To do this, I first create a DbContext instance and then run the following code: var migrator = new MigrateDatabaseToLatestVersion<DataContext, Configuration>(); migrator.InitializeDatabase(this.dataContext); I assumed the database associated with the dataContext's connection would be the one migrated. It appears though that this is not the case. Instead, it always tries to migrate a database on a local SQLExpress instance. There is an overload to the

How Can I generate Identity DB Scripts without migration

帅比萌擦擦* 提交于 2019-12-06 07:55:38
问题 I've been trying to fix a project so it has the db script for IdentityServer4. I've been informed to run dotnet ef migrations add InitialIdentityServerMigration -c PersistedGrantDbContext However when I run that I receive an error: dotnet: No executable found matching command "dotnet-ef" So I followed a few resources for getting dotnet-ef and I Installed a few nuget packagets: Microsoft.EntityFrameworkCore.Tools Microsoft.EntityFrameworkCore.Design but still affter all that I receive the same

C# - Foreign key references invalid table - Basic Migration not working

会有一股神秘感。 提交于 2019-12-06 07:18:10
问题 Trying to make my first project in C#. However, it's very frustrating so far. This is a problem I can't solve, since I don't see anything wrong. I'm trying to just do a simple migrate in my DB. Users migration file public override void Up() { CreateTable( "dbo.Users", c => new { user_id = c.Int(nullable: false, identity: true), first_name = c.String(), last_name = c.String(), email = c.String(), role = c.String(), }) .PrimaryKey(t => t.user_id); } Locations migration file public override void