I don't know if I am doing this right but I basically want to the category names unique in this model
public class Category
{
public int CategoryId { get; set; }
[Required]
public string CategoryName { get; set; }
public string Description { get; set; }
public List<unitItem> itemList { get; set; }
}
I tried using an index and added this to my appDbContext
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Category>()
.HasIndex(b => b.CategoryName).IsUnique();
}
public DbSet<Category> Categories { get; set; }
but when I run I get this error:
The entity type 'IdentityUserLogin' requires a primary key to be defined. If you intended to use a keyless entity type call 'HasNoKey()'.'
Any solution to this would be appreciated.