Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You don't see the relationship being deleted since your proxy is not a change tracking proxy but lazy loading proxy only. To make it a change tracking proxy you need to set all the properties to be virtual. Below please find an example that resets a navigation property without loading it first. Now a question is whether or not to use change tracking proxies - see <a href="http://blog.oneunicorn.com/2011/12/05/should-you-use-entity-framework-change-tracking-proxies/" rel="noreferrer">this post</a> as it contains an interesting discussion on this. </p> <pre><code>public class Computer { public virtual string Id { get; set; } public virtual 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; } } public class MyContext : DbContext { public DbSet&lt;Computer&gt; Computers { get; set; } public DbSet&lt;User&gt; Users { get; set; } } class Program { static void Main(string[] args) { using (var ctx = new MyContext()) { if (!ctx.Computers.Any()) { var user = ctx.Users.Add(new User()); ctx.Computers.Add(new Computer() { Id = "MyComputer", User = user }); ctx.SaveChanges(); } } using (var ctx = new MyContext()) { var computer = ctx.Computers.Single(); computer.User = null; ctx.SaveChanges(); } using (var ctx = new MyContext()) { var computer = ctx.Computers.Include("User").Single(); Console.WriteLine(computer.User == null); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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