asp.net - EntityFramework - Refresh my context to check DB changes -
i've web.api working fine, until modify directly in db, , api returns old value because it's not refreshed.
example:
public class myrepository { private static mycontext datacontext = new mycontext(); public static list<invite> getallinvitesbyuser(string userid) { ... ienumerable<tinvite> results = in datacontext.invites ... select i;
it returns json:
{ "invite": { "idinvite": 374, "message": "hi there", "type": 0, ...
if go database, , update 1 field:
update tinvite set type = 1 idinvite = 374
how can make api return type=1 without restarting iis?
update
my context looks this:
public mycontext() : base("myentities") { configuration.proxycreationenabled = false; configuration.lazyloadingenabled = false; }
when check in real time database queries sql server profiler, see ef makes right query, in case:
exec sp_executesql n'select [extent1].[idinvite] [idinvite], [extent1].[message] [message], [extent1].[type] [type], ... [dbo].[tinvite] [extent1] ...
which should return type = 1, datacontext.invites object has old value type (0)...
why making query if it's ignoring result , using context values??
if don't want store entities in local context storage, can use asnotracking()
extension method:
context.invites.asnotracking().where(...);
Comments
Post a Comment