Entity Framework - First Code Approach

I just follow the first approach to the entity base code in my project, and I got into some problems. I always have to restore db with commands. however, now I manage to get this stable. I have a script, and in this, the structure creates the migration script is not logical, maybe I'm missing something and I need your help in this

Scenario - I turned on migration and created the InitialCreate class with all the settings for my table, I was very impressed. but when I make changes to the entity, for example, I have a class class

I added a new LenderName property, BorrowerName and ran the add-migration script, it created a migration script for me,

 public partial class LenderBorrowerName : DbMigration
    {
        public override void Up()
        {
            DropColumn("dbo.Deals", "LenderName");
            DropColumn("dbo.Deals", "BorrowerName");
            DropColumn("dbo.Deals", "Discriminator");
        }

        public override void Down()
        {
            AddColumn("dbo.Deals", "Discriminator", c => c.String(nullable: false, maxLength: 128));
            AddColumn("dbo.Deals", "BorrowerName", c => c.String());
            AddColumn("dbo.Deals", "LenderName", c => c.String());
        }
    }

, script . , update-migration -force, - up() , . Microsoft drop script, ? ,

+4
1

: Discriminator. EF , TPH, Table-Per-Hierarchy. Discriminator EF, .

, , : , , . , DbContext DbSet , . , , DbContext DbSets ( ). , DbContext, , EF , , DropColumn.

, , DbSet DbContext .

TPH.

, Update-Database Add-Migration -force , __MigrationHistory. , , Initial .

0

Source: https://habr.com/ru/post/1661321/


All Articles