sql - FirstOrDefault call in entity framework is cached but database is changed -
i have unusual issue, haven't experienced before. utilize entity framework retrieve records.
i have next call:
var dborganisation = repository.dborganisation.firstordefault(c => c.id == id); i expect no caching of call. when create call, expect query database , retrieve latest dborganisation object. not happens.
i phone call method relatively 2 times relatively short time after eachother (~5-10 seconds). in period, decimal value in table, can changed 3rd party.
however, though value changes, firstordefault phone call retrieves not updated version.
example situation:
i createfirstordefault call, , see decimal value of field credits, 50 a 3rd party changes credits 45 i create firstordefault phone call 10 seconds, later, dborganisation still have 50 in credits what doing wrong? thought firstordefault phone call not cached default?
you doing correct, that's how ef works.
you can utilize .asnotracking() purposes:
var dborganisation = repository.dborganisation.asnotracking().firstordefault(c => c.id == id); dbextensions.asnotracking method: returns new query entities returned not cached in dbcontext or objectcontext.
sql entity-framework caching entity-framework-5
No comments:
Post a Comment