Base solution for your next web application
Open Closed

Help with update of included entities #6345


User avatar
0
pointlevel created

Hi!

Need help with updating an entity thats included as an ICollection. I believe this is a simple task, but my brain is refusing to collaborate with me.

var stuff = _myRepository.GetAll().Include(x => x.MyList).Where(c => c.Condition == true)

How do i update the included "MyList" above. I also need to include some conditions before update (if/else etc..). Also i want to update the "main"-entitie at the end.

`

foreach (Item item in stuff.MyList)
{
    if (item == something)
    {
    // Update the entity.
    }
}

Big thanks in advance.


1 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    According to your above, MyList has been tracked by EF. All you can update it. (foreach no problem)