Answers for "efcore set sttribute as unique"

1

ef code first unique constraint

//single index
[Index("IX_First", IsUnique = true)]
public int FirstColumn { get; set; }

// composite index
[Index("IX_FirstAndSecond", 1, IsUnique = true)]
public int FirstColumn { get; set; }

[Index("IX_FirstAndSecond", 2, IsUnique = true)]
public int SecondColumn { get; set; }
Posted by: Guest on April-02-2020
0

how to set unique constraint from EF core

protected override void OnModelCreating(ModelBuilder builder)
{
    builder.Entity<User>()
        .HasIndex(u => u.Email)
        .IsUnique();
}
Posted by: Guest on February-27-2020

Browse Popular Code Answers by Language