title: How to make a property unique in Entity Framework Code First
body: <p>This is my <code>User</code> model Class:</p>
  
  <pre><code>public class User 
  {
      public int Id { get; set; }
  
      [Required]
      [MaxLength(100)]
      public string FullName { get; set; }
  
      [Required]
      [MaxLength(30)]
      [Remote("IsUsernameExists", "Home", HttpMethod = "Post")]
      public string UserName { get; set; }
  
      [Required]
      [RegularExpression(@"^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$"]
      public string Email { get; set; }
  
      [Required]
      [StringLength(maximumLength: 18, MinimumLength = 8)]
      public string Password { get; set; }
  }
  </code></pre>
  
  <p>This is <code>IsUsernameExists</code> method in <code>Home</code> controller</p>
  
  <pre><code>public JsonResult IsUsernameExists(string UserName)
  {            
      return Json(!db.Users.Any(x =&gt; x.Username == UserName), JsonRequestBehavior.AllowGet);
  }
  </code></pre>
  
  <p>But it doesn't work. Any further help will highly be appreciated!</p>