If I plan to use data caching do I have to worry about conflicts when also using deferred loading? It seems that with linq I am losing control of my data.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Both LinqToSql and EntityFramework provide both features (deferred loading and data caching).
For example, if you initially load a Customer, that Customer will be cached and if you ask for it again you’ll get the same instance.
If you don’t load a Customer’s Orders during that initial load, then the Orders property of that Customer instance will be in an unloaded state. When you do load those orders, then the Order instances will be available through that property.
In both technologies, the Context is the thing that does the caching… so if you use more than one Context instance – you could observe different Customer instances that really represent the same Customer.
Addressing your questions in comments. I’ll be talking LinqToSql, but this stuff should work in EntityFramework as well.
Yes, that will work. However, they are not totally independent.
There is no flushing or resetting the cache. If you want a fresh cache, the thing to do is to create a new DataContext. Each instance of DataContext has its own cache.