Hi, what is the equivalent of db.refresh(); in asp.net core2. is it db.SaveChanges();?
Thanks.
I think you are referring to ObjectContext.Refresh Method
Currently, there is no equivalent of it in asp.net core or EF Core, context.Entry(foo).Reload()
is currently the closest thing, but it only works on a single entity.
In general, it is recommended to use short-lived contexts that cover a single unit-of-work (That is, create a context instance, query for the relevant entities, make changes, save changes, dispose of the context. check https://www.martinfowler.com/eaaCatalog/unitOfWork.html for info on the unit-of-work-pattern). This usually makes reloading from the store unnecessary.
Reload
and ReloadAsync
has been available since Entity Framework Core 1.1, this can be use to Refresh DbContext in EF Core (.NET core)
//If ex.Name is "Hello World"
var ex = dbContext.Tests.FirstOrDefault();
ex.Name = "Hello";
//ex.Name is now "Hello World" again
dbContext.Entry(ex).Reload();
That's it.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly