title: The relationship could not be changed because one or more of the foreign-key properties is non-nullable when updating
body: <p>I have some problems when updating my model. This is my update code:</p>
  
  <pre><code>public void Update(Class @class)
  {
      var updatedClass = context.Classes.Where(c =&gt; c.ClassId == @class.ClassId).FirstOrDefault();
      updatedClass.ClassPriceTypeId = @class.ClassPriceTypeId;
      updatedClass.ClassType = @class.ClassType;
      updatedClass.Name = @class.Name;
      updatedClass.Title = @class.Title;
      updatedClass.MetaTag = @class.MetaTag;
      updatedClass.MetaDescription = @class.MetaDescription;
      updatedClass.UrlSafe = @class.UrlSafe;
      updatedClass.Header = @class.Header;
      updatedClass.Margin = @class.Margin;
      updatedClass.ImageName = @class.ImageName;
      updatedClass.GroupId = @class.GroupId;
      updatedClass.IsPublished = @class.IsPublished;
      context.SaveChanges();
  }
  </code></pre>
  
  <p>First problem is that I have made <code>LazyLoadingEnabled=false</code> but after fetching <code>updatedClass</code> the relational properties like <code>Group</code> is not null.</p>
  
  <p>Second problem is that in some of <code>@class</code> objects I can easily update my entity but in some others I see this error:</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><strong>Update</strong></p>
  
  <p>This is <code>Class</code> model:</p>
  
  <pre><code>public class Class
  {
      public int ClassId { get; set; }
      public int GroupId { get; set; }
      public int ClassPriceTypeId { get; set; }
      public string Name { get; set; }
      public string Title { get; set; }
      public string MetaTag { get; set; }
      public string MetaDescription { get; set; }
      public string UrlSafe { get; set; }
      public string Header { get; set; }
      public string ImageName { get; set; }
      public int Margin { get; set; }
      public string ClassType { get; set; }
      public bool IsPublished { get; set; }
      public virtual Group Group { get; set; }
      public virtual List&lt;Product&gt; Products { get; set; }
      public virtual List&lt;Comparing.Model.Price.Price &gt; Prices { get; set; }
      public virtual ClassPriceType.ClassPriceType ClassPriceType { get; set; }
      public virtual List&lt;Garanty&gt; Garanties { get; set; }
      public virtual List&lt;PhoneModel&gt; PhoneModels { get; set; }
      public virtual List&lt;ClassPartner&gt; ClassPartners { get; set; }
      public virtual List&lt;Content&gt; Contents { get; set; }
  }
  </code></pre>
  
  <p>And this is <code>Group</code> model:</p>
  
  <pre><code>public class Group
  {
      public int GroupId { get; set; }
      public int SectionId { get; set; }
      public string Name { get; set; }
      public string Title { get; set; }
      public string MetaTag { get; set; }
      public string MetaDescription { get; set; }
      public string UrlSafe { get; set; }
      public string Header { get; set; }
      public string ImageName { get; set; }
      public bool IsPublished { get; set; }
      public virtual Section Section { get; set; }
      public virtual List&lt;Class&gt; Classes { get; set; }
  }
  </code></pre>
  
  <p>Can anyone help me about the problem?</p>