SQL Caching and Entity Framework

前端 未结 2 1689
深忆病人
深忆病人 2021-02-04 16:06

I have put together a small ASP.NET MVC 2 site that does some very extensive date mining/table-joins/etc.

Using MVC, I have a controller that returns the data in many

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-04 16:55

    It is possible to wrap any arbitrary LINQ query in a SqlDependency, including EF Linq queries, see LinqToCache. But unfortunately the way EF chooses to formulate the SQL for the queries, even the most simple from t in context.table select t, is incompatible with the Query Notificaiton restriction and the SqlDependency is invalidated straight away as an invalid statement. I have talked about this in SqlDependency based caching of LINQ Queries.

    What you can do is use SqlChangeMonitor with straightforward SqlCommand objects constructed as simple SELECT ... FROM Table on your tables that are likely to change. You need to understand that there is a balance between the cost of setting up notifications and the cost of polling, if your tables change frequently then monitoring for changes could turn out to be more expensive than polling. See this article The Mysterious Notification to understand how QN works and what is the cost of monitoring.

提交回复
热议问题