Note that there are some explanatory texts on larger screens.

plurals
  1. PORemoving a navigation property doesn't update the database
    primarykey
    data
    text
    <p>I have 2 POCO classes (below) and wish to remove the link between two of their records. According to <a href="http://msdn.microsoft.com/en-us/data/jj713564.aspx" rel="nofollow">this</a> EF 5.0 should be able to handle the removal without loading the User class like so:</p> <pre><code>context.Computers.Find("test").User = null; context.SaveChanges(); </code></pre> <p>This doesn't work, but using the .net 4 approved method it works:</p> <pre><code>en = context.Computers.Find("test"); context.Entry(en).Reference(e =&gt; e.User).Load(); en.User = null; context.SaveChanges(); </code></pre> <p>My EF reference is EntityFramework.dll version 5.0.0.0. Am I missing something obvious here?</p> <p>Here are the classes:</p> <pre><code>public class Computer { public string Id { get; set; } public Nullable&lt;int&gt; UserId { get; set; } public virtual User User { get; set; } } public class User { public int Id { get; set; } public virtual ICollection&lt;Computer&gt; Computers { get; set; } } </code></pre> <p>Edit: Here is the specific lines in the above linked article that don't seem to agree with the functionality I'm seeing: </p> <p>To delete the relationship, set the navigation property to null. If you are working with the Entity Framework that is based on .NET 4.0, then the related end needs to be loaded before you set it to null. For example:</p> <pre><code>context.Entry(course).Reference(c =&gt; c.Department).Load(); course.Department = null; </code></pre> <p>Starting with the Entity Framework 5.0, that is based on .NET 4.5, you can set the relationship to null without loading the related end.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload