Hi EuroEager2008-7858,
>>I have tried with both .HasAlternateKey() and .HasIndex().IsUnique(), but I can still add mentioned rows data.
In general, you can use HasIndex() and to add indexes for migration through fluent API. So in order to find the cause more accurately, please provide the code you tried.
Code likes below:
modelBuilder.Entity<Blog>()
.HasIndex(b => b.Url)
.IsUnique();
And I found some code example using fluent API to create a constraint you can refer to.
Setting unique Constraint with fluent API?
Entity Framework Core add unique constraint code-first
Unique Key constraints for multiple columns in Entity Framework
Hope these are helpful to you.
Best Regards,
Daniel Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.