0

I have an Employee class:

public class Employee
{
    [Key]
    public string ID{ get; set; }

    [Unique]
    public string EmployeeID { get; set; }
}

The ID becomes the primary key. However, I want the EmployeeID to be a unique key as well.

Is there any data annotation to make the EmployeeID field unique?

These are the packages that I am using in my project:

These are the packages that I am using in my project

I have tried using [Index(IsUnique=true)]. But I need to install a new package for this.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Adi
  • 405
  • 1
  • 7
  • 13
  • Does this answer your question? [Entity Framework code first unique column](https://stackoverflow.com/questions/10614575/entity-framework-code-first-unique-column) – devlin carnate Aug 27 '20 at 17:35
  • I tried this. However, I need to install new packages in my project and I am not allowed t do so. – Adi Aug 27 '20 at 17:38
  • 1
    Why are you not allowed to install new packages? Is that a corporate decision? If you want a data annotation that is in a package you can't install because of corporate policies, I'm afraid you're out of luck. – Robert Harvey Aug 27 '20 at 17:54

0 Answers0