Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IndexAnnotation to EF Core

I have this code in EF 6.2

public class ClientNotificationMap : EntityTypeConfiguration<ClientNotification>
{
    public ClientNotificationMap()
    {
        HasKey(x => x.RelationalId);

        Property(x => x.SubscriptionId)
            .IsRequired()
            .HasMaxLength(400)
            .HasColumnAnnotation(IndexAnnotation.AnnotationName, new  IndexAnnotation(new IndexAttribute()));
     }
}

which I want to migrate to Core 2.2

public class ClientNotificationMap : IEntityTypeConfiguration<ClientNotification>
{
    public ClientNotificationMap()
    {

    }

    public void Configure(EntityTypeBuilder<ClientNotification> builder)
    {
        builder.HasKey(x => x.RelationalId);

        builder.Property(x => x.SubscriptionId)
            .IsRequired()
            .HasMaxLength(400)
            .HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute()));
    }
}

Does anyone know how to change the

                .HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute()));

In Core it doesn't seem to be supported. Also I don't find anything relative to the web.

like image 535
user3417479 Avatar asked Dec 29 '25 19:12

user3417479


2 Answers

In the end I wrote the code

        builder.HasIndex(x => x.SubscriptionId)
            .IsUnique();

        builder.Property(x => x.SubscriptionId)
            .IsRequired()
            .HasMaxLength(400);

it compiles at least

like image 116
user3417479 Avatar answered Dec 31 '25 13:12

user3417479


It should be something like this:

builder.HasIndex(x => new { x.SubscriptionId})
.HasDatabaseName("IX_SubscriptionId")
.HasFilter(null)
.IsUnique(true);
like image 42
error505 Avatar answered Dec 31 '25 12:12

error505