What is equivalent of db.refresh(), in asp.net core2


Hi, what is the equivalent of db.refresh(); in asp.net core2. is it db.SaveChanges();?

Thanks.


Asked by:- LuneAgile
0
: 1547 At:- 10/18/2018 10:46:48 AM
ASP.NET save-data







2 Answers
profileImage Answered by:- manish

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.

2
At:- 10/18/2018 11:48:10 AM Updated at:- 10/18/2018 11:50:32 AM
Thanks. Manish. 0
By : LuneAgile - at :- 10/18/2018 7:22:24 PM


profileImage Answered by:- vikas_jk

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.

0
At:- 9/27/2022 7:32:47 AM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use