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 7058251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:05:25+00:00 2026-05-28T04:05:25+00:00

I have a Supplier entity, each Supplier object may reference another Supplier object as

  • 0

I have a Supplier entity, each Supplier object may reference another Supplier object as its ‘parent’.

public class Supplier
{
    public int? Id { get; set; }

    public virtual Supplier Parent { get; set; }
}

This all works as expected until I attempt to remove the relationship, as in, this supplier no longer has a parent. I can change it from null to a particular supplier and I can set it to a different supplier but setting it to null is not persisted after SaveChanges().

supplier.Parent = null;

The foreign key ‘ParentId’ in the Supplier table is set as nullable. Explicitly defining the relationship doesn’t help.

modelBuilder.Entity<Supplier>().HasOptional(s => s.Parent).WithMany();

I’m sure I’m missing something obvious.

  • 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-05-28T04:05:26+00:00Added an answer on May 28, 2026 at 4:05 am

    Just found another place in my code where I do the exact same thing (that works) and found this;

    // Must access property (trigger lazy-loading) before we can set it to null (Entity Framework bug!!!)
    var colour = modelItem.Colour;
    modelItem.Colour = null;
    

    Did the same in the new code and it all works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I Supplier class: public class Supplier { .... .... .... } I have also
I have ThirdParty entity and two derived entities: Supplier and Customer. I have another
I have suppliers table with id int value for each supplier. I'm trying to
We have a product that uses a Reference from a 3rd party supplier. With
I have a method that counts the number of Contacts each Supplier, Customer and
I have a Project entity and a Group entity. I can get a Project
Having odd problem with mapping tables with code-first EF. I have a parent class
I have two classes. One is the entity class, the other serves as a
We have a supplier who provides a library for access to their hardware. Unfortunately,
I have a question regarding JPA persistence in Glassfish. Situation: I have a Supplier

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.