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

  • Home
  • SEARCH
  • 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 6745825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:15:01+00:00 2026-05-26T12:15:01+00:00

Issue: Child model collection in MVC3 & Entity Framework 4.1 is being updated properly

  • 0

Issue: Child model collection in MVC3 & Entity Framework 4.1 is being updated properly in model via Edit action but the values are not being saved in DB.

Overview:
– Model object Person contains object CaseRef’s
– Person property updates are getting saved in the DB on db.SaveChanges() but internal collection CaseRef property updates are not being saved
– All values are bound/mapped correctly upon entry of HttpPost ActionResult Edit() so the model is being updated successfully from Form submit (Edit View).

Models:

public  class Person
{
    public Person()
    {
        this.CaseRefs = new HashSet<CaseRef>();
    }  
   // <...more properties here...>
    public string Name { get; set; }
    public int UserId {get; set}

    public virtual ICollection<CaseRef> CaseRefs { get; set; }     
}

public  class CaseRef
{
   // <...more properties here...>
   public int DescId { get; set; }  
   public virtual Person Person { get; set; }  
}

Controller – Edit (Post)

    [HttpPost]
    public ActionResult Edit(Person p)
    {
        if (ModelState.IsValid)
        {
            // NOTE: At this point all fields from Edit form have been saved to the model
            //       specifically the internal CaseRefs Collection value updates.
            db.Entry(p).State = EntityState.Modified;

            // This is saving changes to Person.Name but not saving changes to the updated
            // values in CaseRefs collection
            db.SaveChanges();  
            return RedirectToAction("Index");
        }
  • 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-26T12:15:02+00:00Added an answer on May 26, 2026 at 12:15 pm

    Setting db.Entry(p).State = EntityState.Modified; you only set the parent entity to modified. To also modify the navigational properties you have to mark them all as modified.

    So something like: p.CaseRefs.ForEach(c => db.Entry(c).State = EntityState.Modified);

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

Sidebar

Related Questions

I'm having problems with updating a child model via nested form. I've read many
I am having an issue removing the master -> child link fields in an
Our issue is that our project has files being downloaded using wget to the
I am a pretty much a newbie to Entity Framework (specifically version 4) and
I have an issue when deleting a child record from the session. Here are
I'm trying to get the average value of an attribute in a child entity
I am having an issue with a custom control rendering its contents (child controls)
In a current Flex project, i have an issue where a certain child component
I have a primefaces dataList within a primefaces dataGrid but I'm having issue mapping
For entity ParentEntity with a collection of type ChildEntity which contains an Order property

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.