© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•15mo ago•
63 replies
Jiry_XD

✅ EF Core doesn't stop tracking list items.

Trying to edit an office entity and this works great for everything, except when the editedOffice passes less salesPerson ID's then there were before. If there are less id's it should remove them from the list inside the db aswell, currently it's not doing that. It is however adding new ones correctly when you pass more ids that werent there before.
public async Task<OfficeDTO?> EditOfficeAsync(OfficeEditDTO editedOffice)
{
    var office = await dbContext.Offices.Include(o => o.Address)
                                         .Include(o => o.SalesPeople)
                                         .FirstOrDefaultAsync(o => o.Id == editedOffice.Id);

    if (office == null)
        return null;

    var selectedSalesPeopleIds = office.SalesPeople.Select(o => o.Id).ToList();


    if (editedOffice.Name != null)
        office.Name = editedOffice.Name;

    if(editedOffice.Address != null)
    {
public async Task<OfficeDTO?> EditOfficeAsync(OfficeEditDTO editedOffice)
{
    var office = await dbContext.Offices.Include(o => o.Address)
                                         .Include(o => o.SalesPeople)
                                         .FirstOrDefaultAsync(o => o.Id == editedOffice.Id);

    if (office == null)
        return null;

    var selectedSalesPeopleIds = office.SalesPeople.Select(o => o.Id).ToList();


    if (editedOffice.Name != null)
        office.Name = editedOffice.Name;

    if(editedOffice.Address != null)
    {
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

EF Core - Tracking problems while updating
C#CC# / help
3y ago
❔ EF Core Person Task List
C#CC# / help
3y ago
✅ I want to get duplicate items in my List (EF Core)
C#CC# / help
4y ago
❔ Ef tracking issue
C#CC# / help
4y ago