title: Getting exception while deleting object from navigation property in one to many relationship entityframework
body: <p>I am using EF code first in my project. The POCO classes and fluent api are as follows:</p>
  
  <p><strong>POCO classes</strong></p>
  
  <pre><code>public class Tenant
  {
    public int TenantId { get; set; }
  
    public virtual ICollection&lt;Service&gt; Services { get; set; }
  } 
  
  public class Service
  {
    public int ServiceId { get; set; }
  
    public int TenantId { get; set; }
    public virtual Tenant Tenant { get; set; }
  } 
  </code></pre>
  
  <p><strong>Fluent Api</strong></p>
  
  <pre><code>   modelBuilder.Entity&lt;Tenant&gt;()
                 .HasMany(p =&gt; p.Services)
                 .WithRequired(p =&gt; p.Tenant)
                 .HasForeignKey(p =&gt; p.TenantId)
                 .WillCascadeOnDelete(false);
  </code></pre>
  
  <p>The relationship between Tenant and Service is 1 to many bidirectional. When i am trying to delete Service from the list of services like this:</p>
  
  <pre><code>  tenantProvider.Tenant.Services.Remove(service);
  </code></pre>
  
  <p>I got this exception:</p>
  
  <blockquote>
    <p>The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted.</p>
  </blockquote>
  
  <p>Can anybody please me out and tell me what i am doing wrong ??
   (Because of other relationships in my schema and multiple cascade path i have to set cascade delete false)</p>
  
  <p><strong>Edit</strong></p>
  
  <p>The answer given by <em>@Kirill Bestemyanov</em> solved my issue and now i can successfully delete the service from <em>Service</em> table. But still i don't understand why i was getting the above mentioned exception when i was trying to delete the service from <em>Services</em> navigation property of <em>Tenant</em> entity. Can anyone please explain me briefly ??</p>
  
  <p>Thanks! </p>