title: ASP.NET MVC 4, EF5, Unique property in model - best practice?
body: <p>ASP.NET MVC 4, EF5, <strong>Code First</strong>, SQL Server 2012 Express</p>
  
  <p>What is best practice to enforce a unique value in a model? I have a places class that has a 'url' property that should be unique for every place.</p>
  
  <pre><code>public class Place
  {
        [ScaffoldColumn(false)]
        public virtual int PlaceID { get; set; }
  
        [DisplayName("Date Added")]
        public virtual DateTime DateAdded { get; set; }
  
        [Required(ErrorMessage = "Place Name is required")]
        [StringLength(100)]
        public virtual string Name { get; set; }
  
        public virtual string URL { get; set; }
  };
  </code></pre>
  
  <p>Why isn't there just a [Unique] data annotation you can place on it?</p>
  
  <p>I have seen 1 or 2 discussions on this, but no talk of best practice. Using Code First can you somehow tell the database to set a unique constraint on the field in the database?</p>
  
  <p>What is easiest way - and what is best practice? </p>