title: Unique constraint in database-first approach
body: <p>I'm have database with many unique constraints.</p>
  
  <p>I'm aware of that entity framework doesn't know anything about them. So I need to add them to the model manually. But in</p>
  
  <pre><code>System.ComponentModel.DataAnnotations
  </code></pre>
  
  <p>There is no Unique keyword.</p>
  
  <p>I created new attribute:</p>
  
  <pre><code>[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
  public class UniqueKeyAttribute : Attribute
  {
  }
  </code></pre>
  
  <p>and added it to my model:</p>
  
  <pre><code>[MetadataType(typeof(DeviceInstance))]
  public partial class DeviceInstance
  {
      public int Id { get; set; }
      [Required]
      public int DeviceId { get; set; }
      [Required]
      [UniqueKey]
      [MaxLength(50)]
      public string SerialNo { get; set; }
      [Required]
      public System.DateTime CreationDate { get; set; }
  }
  </code></pre>
  
  <p>Even that
  <code>Model.IsValid</code> is always returning true even if there is already that value in the table.</p>
  
  <p>What code should I write to change this behavior? </p>