-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Closed
Closed
ef migrations add keep add the same AlterColumn migration content for strongly-typed primary key#30699Bug
Copy link
Milestone
Description
To Reproduce
Create a new project and install packages:
Microsoft.EntityFrameworkCore.DesignMicrosoft.EntityFrameworkCore.Sqlite
Then add some codes:
public class TheDbContext : DbContext
{
public DbSet<TheEntity> TheEntities { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<TheEntity>()
.Property(e => e.Id)
.HasConversion(new TheId.EntityFrameworkCoreValueConverter());
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseSqlite(":memory:");
}
public record TheEntity
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public TheId Id { get; set; }
}
public record struct TheId(int Value)
{
public class EntityFrameworkCoreValueConverter : ValueConverter<TheId, int>
{
public EntityFrameworkCoreValueConverter() : this(default) { }
public EntityFrameworkCoreValueConverter(ConverterMappingHints? mappingHints = default)
: base(e => e.Value, value => new(value), mappingHints)
{
}
}
}Now, every time I call dotnet ef migrations add (New-Guid).ToString().Substring(0, 8), it will generated the same content:
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "Id",
table: "TheEntities",
type: "INTEGER",
nullable: false,
oldClrType: typeof(int),
oldType: "INTEGER")
.OldAnnotation("Sqlite:Autoincrement", true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "Id",
table: "TheEntities",
type: "INTEGER",
nullable: false,
oldClrType: typeof(int),
oldType: "INTEGER")
.Annotation("Sqlite:Autoincrement", true);
}Include provider and version information
EF Core version: 7.0.5
Database provider: Microsoft.EntityFrameworkCore.Sqlite
Target framework: .NET 7.0
Operating system: Windows 11 x64
IDE: Visual Studio 2022 17.5.4
macias, dagophil, AlKo77, ManuelGit-Hub, jekajarkov and 5 more