I was just learning how to use the LINQ/EDM combination to retrieve and update a simple user-thread-and-comment webapp as part of evaluating it.
When I turn on SQL Profiler, I rarely see a SQL statement executed by my app. I'm starting to really like how well it keeps things cached, coz as soon as I add new data, it magically updates itself while I'm blinking.But is that something I should be scared of?
My concern is when I use this to make a webapp with some traffic (whatever hit count that reaches this approach's par). Should I keep a single context object at app-level, so that different sessions can benefit from each other's cache entries? Or should I do the create-and-release on each page submission?I know this sounds like an open-ended question, but I really have that as a question: how does the entity cache its 开发者_运维技巧data when using LINQ?
On the ObjectContext
question you should use a lifetime of per-page-request cycle or smaller. It's designed for a unit of work and not for the application lifetime. Search SO for "ObjectContext lifetime" or "DataContext lifetime" and you'll see this is a common question.
精彩评论