I can\'t find way to add a unique constraint to my field with using attribute:
public class User
{
[Required]
public int Id { get; set; }
[Requi
Ef core support unique configuration.
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity()
.HasIndex(account => account.Email)
.IsUnique();
}
Ef core support multiple unique keys
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity()
.HasKey(account => new { account.Id, account.Email, account.RoleId });
}
Don't forget run ef core command to make migration and update the database
>> dotnet ef migrations add MigrationName -c YourDbContextName
>> dotnet ef database update -c YourDbContextName