Linq2Sql Caching with SqlDependency
Posted by Shaun McDonnell on November 25, 2009
It took me a while to figure this one out. I almost thought it was impossible to implement it in a ‘good way’. However, extension methods saved the day. So, if you want to use Sql Service Broker dependencies in your Linq2Sql code, you’ll need an extension method like this:
Now, in order to use this extension method in your queries, you’ll need to do something like this:
The downside is that I haven’t figured out a good way to implement this when retrieving one record from the database. So, you’ll have to do this:
MSDN did have some code similar to this but it did not work and there were no examples. This works and and the examples should be enough to get you started.