Skip to content

EF Core Sqlite - Migration doesn't apply configuration when [NotMapped] property is added to one of the DbSets #35223

Open
@mhenkrich-wh

Description

@mhenkrich-wh

Hi,

I am getting different output for migration files when I include [NotMapped] property to one of the DbSets.

When I call migration I get:

  migrationBuilder.CreateTable(
      name: "Defects",
      columns: table => new
      {
          Id = table.Column<string>(type: "varchar(36)", nullable: false),
          LastModifiedDateUtc = table.Column<long>(type: "bigint", nullable: false),
          LastClientModifiedDateUtc = table.Column<long>(type: "bigint", nullable: true),
          WorkStepId = table.Column<string>(type: "varchar(36)", nullable: true)
      },

When I add not mapped entity to one of the DbSets,:

[NotMapped]
public IEnumerable<EntryEf> Entries => Defects.Cast<EntryEf>().Concat(Expenses);

Then when I delete migration and create new one the output of the new migration is:

     migrationBuilder.CreateTable(
         name: "Defects",
         columns: table => new
         {
             Id = table.Column<Guid>(type: "TEXT", nullable: false),
             LastModifiedDateUtc = table.Column<DateTime>(type: "TEXT", nullable: false),
             LastClientModifiedDateUtc = table.Column<DateTime>(type: "TEXT", nullable: true),
             WorkStepId = table.Column<string>(type: "varchar(36)", nullable: true)
         },

Which is completely different, and I added only [NotMapped] property.

In order to fully reproduce bug I created repo:
https://github.com/mhenkrich-wh/EntityFrameworkCore_Bug_11_27_24

Steps to reproduce:

  1. Build -> Add migration "Add-migration test1" -> inspect migration.
  2. In file WorkStep.cs comment out lines 22 and 23 (this mapped property)
  3. Delete current migration
  4. Build -> Add migration "Add-migration test2" -> inspect migration.

You can see that test1 migration output doesn't match test2 migration output.
To me it seems like custom configuration is not applied.

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions