title: Specify ON DELETE NO ACTION in ASP.NET MVC 4 C# Code First
body: <p>How do I specify ON DELETE NO ACTION Foreign Key Constraint in my model designs?</p>
  
  <p>At present, I have:</p>
  
  <pre><code>public class Status
  {
      [Required]
      public int StatusId { get; set; }
  
      [Required]
      [DisplayName("Status")]
      public string Name { get; set; }
  }
  
  public class Restuarant
  {
      public int RestaurantId { get; set; }
      [Required]
      public string Name { get; set; }
      [Required]
      [EmailAddress]
      public string Email { get; set; }
      [Required]
      public string Telephone { get; set; }
      [Required]
      public int StatusId { get; set; }
      public List&lt;Menu&gt; Menus { get; set; }
  
      // NAVIGATION PROPERTIES
      public virtual Status Status { get; set; }
  }
  
  public class Menu
  {
      public int MenuId { get; set; }
  
      [Required]
      public int RestaurantId { get; set; }
  
      [Required]
      public string Name { get; set; }
  
      [Required]
      public int StatusId { get; set; }
  
      // NAVIGATION PROPERTIES
      public virtual Status Status { get; set; }
      public virtual Restaurant Restaurant { get; set; }
  }
  </code></pre>
  
  <p>And my DbContext:</p>
  
  <pre><code>public class MenuEntities : DbContext
  {
      public DbSet&lt;Status&gt; Statuses { get; set; }
      public DbSet&lt;Restaurant&gt; Restaurants { get; set; }
      public DbSet&lt;Menu&gt; Menus { get; set; }
  }
  </code></pre>
  
  <p>As you can see: </p>
  
  <ul>
  <li>a Restaurant has many menus</li>
  <li>a Restaurant has one status</li>
  <li>a Menu belongs to 1 restaurant</li>
  <li><strong>Both Restaurants and Menus have 1 status. (Live, Invisible, Draft)</strong></li>
  </ul>
  
  <p>Naturally, if a status is deleted, I certainly don't want to cascade as this will muck everything up.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Mark Oreta mentions using the following in his example below:      </p>
  
  <pre><code>modelBuilder.Entity&lt;FirstEntity&gt;() 
      .HasMany(f =&gt; f.SecondEntities) 
      .WithOptional() 
      .WillCascadeOnDelete(false); 
  </code></pre>
  
  <p>Where do I put this code? Within my MenuEntities / DbContext class? 
  Can anybody provide an example of this being used?</p>
  
  <p><strong>UPDATE:</strong> 
  Got this bit working now, however this has created a multiplicity constraint error when trying to seed the DB...</p>
  
  <pre><code>Multiplicity constraint violated. The role 'Menu_Status_Source' of the relationship 'LaCascadaWebApi.Models.Menu_Status' has multiplicity 1 or 0..1.
  </code></pre>
  
  <p>My Database Initialiser:</p>
  
  <p><a href="http://pastebin.com/T2XWsAqk">http://pastebin.com/T2XWsAqk</a></p>