How to use SQL Cache Dependency Wtih EF DbContext?
I found this article on using Sql Cache Dependency with Linq2SQL. http://www.dotnetcurry.com/ShowArticle.aspx?ID=263
is it possible to do this same thing in Entity Framework with DbContext?
I have a multi-database app so each DbContext Instance Connection is different depending on the 开发者_C百科user. But I feel like utilizing this technology would be the best way to invalidate the cache.
any help is appreciated.
Chase
Take a look at this, will give you a starting point: http://blogs.msdn.com/b/jkowalski/archive/2009/06/11/tracing-and-caching-in-entity-framework-available-on-msdn-code-gallery.aspx, I tried it and it works fine but I have chosen to use a more custom and light weight approach.
Basically I retrieve the TraceString
which is nothing but the raw SQL from my IQueriable<T>
and create a standard SqlCacheDependency
cache entry.
Your DbContext should live only for single unit of work. In your case for single request processing so there is no reason to involve any database dependency in EF.
精彩评论