title: EF 6, How to delete an Entity without enforcing cascade delete and satisfying Foreign Key restraints
body: <p>I'm trying to figure out how to delete an entity without cascade delete</p>
  
  <p>I'm assuming if i do this right, when i delete a related entity (Country, see below), it will set the Country FK in Client to null and the world is all good</p>
  
  <p><strong>Error</strong></p>
  
  <pre><code>The DELETE statement conflicted with the REFERENCE constraint "FK_dbo.Clients_dbo.Countries_CountryId". The conflict occurred in database "JCE", table "dbo.Clients", column 'CountryId'.
  The statement has been terminated.
  </code></pre>
  
  <hr>
  
  <p>The code i'm using</p>
  
  <pre><code>public class Country : IEntity
  {
      [Required,Key]
      public int Id { get; set; }
  
      [Required,Index]
      public int Code { get; set; }
  
      [Required]
      public string Name { get; set; }
  
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>public class Client : IEntity
  {
  
      [Required,Key]
      public int Id { get; set; }
  
      [Required]
      public String Name { get; set; }
      public String Description { get; set; }
  
      public virtual Country Country { get; set; }
  
  }
  </code></pre>
  
  <p>I use the following model builder</p>
  
  <pre><code>modelBuilder.Entity&lt;Client&gt;()
      .HasRequired(r =&gt; r.Country)
      .WithMany()
      .WillCascadeOnDelete(false);
  </code></pre>
  
  <p>And use the following code to delete a country</p>
  
  <pre><code>Db.Countries.Attach(country);
  Db.Countries.Remove(country);
  Db.SaveChanges();
  </code></pre>
  
  <hr>
  
  <p><strong>Question</strong></p>
  
  <p>What do i need to do to satisfy my requirements?
  Also Please let me know if you see any redundancies or oddities with the code i'm using thanks</p>