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