When I create a Migration on my asp.net core 3.1 application with efcore, it works fine.
dotnet-ef migrations add Dev001 --project ..\Infrastructure\LetzIt.SqlServerDbService\LetzIt.SqlServerDbService.csproj --startup-project .\LetzIt.WebApi\LetzIt.WebApi.csproj
If I just add a new Domain class (entity) and configure on my modelconfiguration builder and run the command:
dotnet-ef migrations add Dev002 --project ..\Infrastructure\LetzIt.SqlServerDbService\LetzIt.SqlServerDbService.csproj --startup-project .\LetzIt.WebApi\LetzIt.WebApi.csproj
The output gives me this error:
ps: sorry for the image, but the error here was too ugly to understand. The main lines are:
System.ArgumentException: At least one object must implement IComparable.
and
Failed to compare two elements in the array.
I searched a lot about this and nothing appears to me. I'm not using any SORT by myself. There is no OrderBy in my code anymore.
Here comes an example of entity configuration:
internal sealed class RoleConfiguration : IEntityTypeConfiguration<Role>
{
public void Configure(EntityTypeBuilder<Role> builder)
{
builder.ToTable("Role");
BuildIndexes(builder);
BuildProperties(builder);
//TableSeed(builder);
}
private void BuildIndexes(EntityTypeBuilder<Role> builder)
{
builder.HasKey(m => m.Id);
builder.HasIndex(m => m.Name).IsUnique();
}
private void BuildProperties(EntityTypeBuilder<Role> builder)
{
builder.Property(m => m.Id)
.HasConversion(p => p.ToGuid(), p => new RoleId(p))
.IsRequired();
builder.Property(p => p.Name)
.HasConversion(p => p.ToString(), p => new RoleName(p))
.HasMaxLength(60);
}
private void TableSeed(EntityTypeBuilder<Role> builder)
{
builder.HasData(
new Role(RoleIdConstants.Admin, RoleNameConstants.Admin),
new Role(RoleIdConstants.Manager, RoleNameConstants.Manager));
}
}
Every single property of my entities are ValueObjects, that`s why I'm using the the HasConversion.
Again, the first Migration works fine. If I delete my migrations now (after created the new entity) and create a Dev001 migration again, IT WORKS!!
It's just doesn`t work if I try to put 2 migrations in a row.
Thanks in advance guys.
Further technical details
It is a bug on stable (what??) version of EFCore.
The link shows the answer: