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.
Recent Announcements
Continue the conversation
Join the Discord to ask follow-up questions and connect with the community
C
C#
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.