© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
7 replies
kopuo.

DbContext.SaveChangesAsync has no effect on the collection of changed objects

Hi. I get products collection from dbContext, change some values and want to save it in the database, but after SaveChangesAsync () is done in the database there are no changes. When previewing objects from dbContext at the end, I also cannot see the edited fields:
var products = await _dbContext.Products.AsEnumerableAsync()

foreach(var p in products)
{
  if(p.Price == 0)
    p.Price = 10
}

await _dbContext.AddRangeAsync(products);

await _dbContext.SaveChangesAsync();
var products = await _dbContext.Products.AsEnumerableAsync()

foreach(var p in products)
{
  if(p.Price == 0)
    p.Price = 10
}

await _dbContext.AddRangeAsync(products);

await _dbContext.SaveChangesAsync();


Product is an entity btw.
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

Similar Threads

✅ WPF thinks my collection has no items
C#CC# / help
3y ago
❔ DbContext
C#CC# / help
4y ago
Looking solution for get query from _dbContext.SaveChangesAsync() for save logs and easier debugging
C#CC# / help
4y ago
✅ System.InvalidOperationException: No database provide has been configured for this DbContext
C#CC# / help
14mo ago