ef-migrations

Execute Code First Migrations on Azure with Remote Connection String

守給你的承諾、 提交于 2019-12-04 18:41:56
I am publishing an Azure Web App, and I'm running into a strange issue executing code first migrations. The remote connection string for this database is working just fine if I do not check "Execute Code First Migrations". However, if I check the box, a strange connection string with a curious misspelling, "ConnetionString", gets injected into the remote web.config: <add name="DbContext_DatabasePublish" connectionString="DbContext_DatabasePublish.ConnetionString" providerName="System.Data.SqlClient" /> This, of course, is not a valid connection string and the EF initializer throws this

Naming conventions for Code First migrations

不打扰是莪最后的温柔 提交于 2019-12-04 18:31:53
问题 We are using code first migrations to keep our database and model in sync. At the moment we have the version number as name for the migration which clearly doesn't work out. The problem is that multiple migrations with the same name where created by different developers independent of each other for their local database. This led to some weird behavior as the IMigrationMetadata.Id was different because of the time stamp but the classes are partial with the same name. What is the way to go to

Entity Framework Code First: One-to-Many and Many-to-Many relationships to same table

两盒软妹~` 提交于 2019-12-04 18:14:05
问题 I have a User model and a Event model in my project. The Event has a creator(User) and has participant(Users) so Event has a one-to-many relationship with User and also a many-to-many relationship to the same table. I had first the one-to-many relationship like this: Public class Event { ... public int CreatedById { get; set; } public virtual User CreatedBy { get; set; } ... } Then when I added the many-to-many relationship the migration doesn't generate the many to many relationship: Public

Azure Web App deployment slots with database migration

不打扰是莪最后的温柔 提交于 2019-12-04 14:07:27
I'm currently running a webApp with several deployment slots (e.g. dev, staging, production). Every Slot is connected to a database (db_dev, db_staging, db_production). I want to deploy to the staging slot and then switch with production. How do database migrations fit in here? I mean, if i deploy a new build with db migrations to staging the db_staging gets updated. What happens if I switch the slots? Do the migrations get applied to db_production? What about downtimes? From my understanding only the URLs are switched, so after the switch the app in the staging slot would point to the db

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

僤鯓⒐⒋嵵緔 提交于 2019-12-04 13:02:45
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 Up() { CreateTable( "dbo.Locations", c => new { loc_id = c.Int(nullable: false, identity: true), loc

How Can I generate Identity DB Scripts without migration

笑着哭i 提交于 2019-12-04 12:31:18
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 error message. Is there another way to get the script for a Identity4 DB? Try running the older style

How do OnModelCreating and non automatic Migrations relate?

孤人 提交于 2019-12-04 11:20:17
问题 When I add a new table that has some relations to my database and then run Add-Migration I see that code is generated in the Up method to add the table and its relations. However, I prefer to define the relation using the fluent API in the OnModelCreating method. How do these two methods interact? Can I delete the code from the Up method that defines the relation for instance? 回答1: Each of them has completely different purpose: OnModelCreating is used for inline fluent-API definitions of your

Can we use EF migrations with MySql

◇◆丶佛笑我妖孽 提交于 2019-12-04 11:15:25
Is there a way to use EntityFramework 4.3 beta with migrations with MySql database? Can we use migrations with MySql Database? Is it possible to use incremental database development with EF code first without me touching the database Theoretically yes. Practically you first need to get (or create yourselves) class derived from System.Data.Entity.Migrations.Sql.MigrationSqlGenerator which will be responsible for generating SQL for MySQL. Here is more about customizing (or rewriting) SQL generation. You can also wait until developers of EF supporting ADO.NET providers include this feature to

Defining many to many relation in code first entity framework

久未见 提交于 2019-12-04 09:39:57
问题 I have 3 classes in my model as you can see below. [Table("UserProfile")] public class UserProfile { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public string UserName { get; set; } public ICollection<MartialArtUserProfile> MartialArtUserProfiles { get; set; } } [Table("MartialArt")] public class MartialArt { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public string Name { get; set; }

Add database trigger with Entity Framework Code First Migrations

喜夏-厌秋 提交于 2019-12-04 09:10:39
问题 I use Entity Framework Migrations for code first to control my database model. It works charming and I can handle until now everything. But now I need to add one database trigger and I would like to do this with EF Migrations and not use a separate sql script for only this case (This would be confusing for clients, esp. after we convinced them that we can handle everything with EF Migrations). My trigger is straight forward and looks like tis: CREATE OR REPLACE TRIGGER [name] BEFORE UPDATE ON