Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9195387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:37:02+00:00 2026-06-17T21:37:02+00:00

I have 2 POCO classes (below) and wish to remove the link between two

  • 0

I have 2 POCO classes (below) and wish to remove the link between two of their records. According to this EF 5.0 should be able to handle the removal without loading the User class like so:

context.Computers.Find("test").User = null;
context.SaveChanges();

This doesn’t work, but using the .net 4 approved method it works:

en = context.Computers.Find("test");
context.Entry(en).Reference(e => e.User).Load();
en.User = null;
context.SaveChanges();

My EF reference is EntityFramework.dll version 5.0.0.0. Am I missing something obvious here?

Here are the classes:

public class Computer
{
    public string Id { get; set; }
    public Nullable<int> UserId { get; set; }
    public virtual User User { get; set; }
}
public class User
{
    public int Id { get; set; }
    public virtual ICollection<Computer> Computers { get; set; }
}

Edit: Here is the specific lines in the above linked article that don’t seem to agree with the functionality I’m seeing:

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:

context.Entry(course).Reference(c => c.Department).Load();
course.Department = null;

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:37:03+00:00Added an answer on June 17, 2026 at 9:37 pm

    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 this post as it contains an interesting discussion on this.

    public class Computer
    {
        public virtual string Id { get; set; }
        public virtual Nullable<int> UserId { get; set; }
        public virtual User User { get; set; }
    }
    
    public class User
    {
        public int Id { get; set; }
        public virtual ICollection<Computer> Computers { get; set; }
    }
    
    public class MyContext : DbContext
    {
        public DbSet<Computer> Computers { get; set; }
        public DbSet<User> 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);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two simple POCO classes; I'm trying to get the MyY property below
I have two POCO classes (Account and Invoice) and as you can see (below
I have a solution with this structure : ProjectName.Domain ==> contains POCO classes (EntityFramework
From what I have read POCO classes should be persistence ignorant and should not
I am learning the usage of POCO classes and relationships between entities. I have
I have some POCO classes which can generally divided into two groups, for example:
I have two POCO classes a User and an Address. Address is a complex
I have an interface ISetting. I have POCO classes the implement this empty interface
I have an ntier solution which has a Domain project for my POCO classes.
I have a simple Poco-Model using abstract classes, and it seems not to work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.