In short: I use Linq for sql, but I have problems with caching
My application is metadata driven, so I donβt want to cache (changes to db should be reflected on the website when the page is refreshed). Is there a way to disable caching? or a way to reset the cache (for example, currently, when I change the data in the database, I have to physically change the code and recompile before I see the results).
And finally, the C # question (I hope the main mistake is on my part). In the code below, if I run method1 , then method2 , then doc2 == doc1 (and I want it to get the original value from db)
It seems to me that this is very strange, since the RecordDictionary class is rotary data (therefore, it is not directly related to the model), and in my code the assignments are in different controllers; but somehow linq to sql is the caching changes applied to doc1 and applying them to doc2 (if I doc2 my application and recompile, then doc2 will be the same as what I expect from it (until I I will change doc1 ))
Given example
public RecordDictionary method1() { RecordDictionary doc1 = genericRepository.GetRecordById( action.AppliesToModelEntityId, 27); //do some stuff to doc1 here return doc1; } public RecordDictionary method2() { RecordDictionary doc2 = genericRepository.GetRecordById( action.AppliesToModelEntityId, 27); return doc2; } public RecordDictionary GetRecordById(int ContainerModelId, int id) { var query = (from dv in _db.DataValues where dv.DataInstance.IsCurrent == true && dv.DataInstance.DataContainer.DataContainerId == id select new { dv.DataInstance.DataContainer.ParentDataContainerId, dv }); RecordDictionary result = CreateRecordColumns( ContainerModelId, query.FirstOrDefault().ParentDataContainerId); result.Id = id; foreach (var item in query) { if (result.ContainsKey(item.dv.ModelEntity.ModelEntityId)) result[item.dv.ModelEntity.ModelEntityId] = item.dv; } return result; }
source share