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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:54:22+00:00 2026-05-16T10:54:22+00:00

When I have a parent Entity hold a list of other entity (one to

  • 0

When I have a parent Entity hold a list of other entity (one to many relationship), I modify this list then call function to save the parent Entity. With the entities has removed from this list, is that the framework will delete them from database? And also the new entity has added to the list will be added to database?
thank for your help!

  • 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-16T10:54:23+00:00Added an answer on May 16, 2026 at 10:54 am

    Assuming you have one to many relationship between Parent and Child, i. e., Parent has ChildList and Child has Parent.
    Looking at the cases. If Parent is in the entity context and you add an instance of Child to ChildList of Parent, and save the context, then Child will be added to the database.

    Parent parent = new Parent() { Name = "parent1" };
    provider.AddToParentSet(parent)
    parent.ChildList.Add(new Child() { Name = "child1" });
    parent.ChildList.Add(new Child() { Name = "child2" });
    parent.ChildList.Add(new Child() { Name = "child3" });
    provider.SaveChanges();
    

    If you remove one of the Child from the ChildList of Parent, and save the context, then you will get an exception because of the foreign key constraint.

    Parent parent = provider.ParentSet.FirstOrDefault();
    parent.ChildList.Remove(parent.ChildList.FirstOrDefault());
    provider.SaveChanges();
    

    If you delete one of the Childs that belong to ChildList of Parent from the context and save the context, it will be successful, it will be removed from database.

    provider.DeleteObject(parent.ChildList.FirstOrDefault());
    provider.SaveChanges();
    

    Above situations are valid for default configuration of an entity model. Entity Framework also provides many options, you can also decide how your entity context behaves.
    You just need to try these and such situations on your own. It will be better I think.

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

Sidebar

Related Questions

I have an abstract entity that 4 other entities inherit from. This relationship works
I have 2 entities in a to-many relationship, Parent-->Child. The Child entity has an
I have a one-to-many mapping between a parent entity and child entities. Now I
As a follow up to this question , I have a parent entity that
Hi I have a parent entity Entity A and it has a one to
I have a Parent <-->> Child relationship (to-many). And the relationship is when i
consider this scenario: I have loaded a Parent entity through hibernate Parent contains a
I have a parent child relationship between 2 classes Parent @Entity @Table(name = PARENT)
I have a Parent entity with a Child entity in a ManyToOne relationship: @Entity
Does a OneToOne entity need to have a ManyToOne relationship to the parent entity

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.