Issues with entityframework core model snapshot in team environment

Viewed 3794

We are in initial development application of ef core. I am not sure how ef core Model snapshot communicates/flows with other components like Migrations and database.I don't know which will first get applied on database either Migrations or Model snapshot and how verifies with migrations under the hood.

My case:

  1. Existing migration & Snapshot available in TFS(Developer tested & committed Migraton & model snapshot from his system).
  2. Dev 2 getting latest from his system and pointing to new database without any pending changes.
  3. when executing update-database he is facing error that column already dropped.

ALTER TABLE DROP COLUMN failed because column 'CreatedDateTime' does not exist in table 'TaskEntityRelationships'.

Simplified snapshot:

modelBuilder.Entity("KrossDelivery.Data.Objects.TaskEntityRelationships.TaskEntityRelationship", b =>
        {
            b.Property<int>("Id")
                .ValueGeneratedOnAdd();

            b.Property<int>("CreationTransactionId");

            b.Property<int>("DeliveryAgentId");

            b.Property<int>("DeliveryExecutiveId");

            b.Property<DateTime?>("EndDateTime");

            b.Property<int?>("LastEditTransactionId");

            b.Property<DateTime>("StartDateTime");

            b.Property<int?>("TaskEntityStatusEventId");

            b.Property<int?>("TaskEntityStatusId");

            b.Property<int>("TaskId");

            b.HasKey("Id");

            b.HasIndex("CreationTransactionId");

            b.HasIndex("DeliveryAgentId");

            b.HasIndex("DeliveryExecutiveId");

            b.HasIndex("LastEditTransactionId");

            b.HasIndex("TaskEntityStatusEventId");

            b.HasIndex("TaskEntityStatusId");

            b.HasIndex("TaskId");

            b.ToTable("TaskEntityRelationships");
        });

simplified Migration:

protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.DropColumn(
            name: "CreatedDateTime",
            table: "TaskEntityRelationships");
}

From code i can understand that CreatedDateTime already dropped from model snapshot.Dev A committed his model snapshot with migration but when Dev2 take latest and point new database it is not working. I don't know how to manage model snapshot and migrations and in which sequence I should commit in TFS?

Please advice.Thanks!

1 Answers

Initially I used EnsureCreated() and now I changed to Migrate() now its working.

Related