Search code examples
c#asp.netlinq-to-sqlrepository-patternsqlcachedependency

SqlCacheDependency with LINQ2SQL (Repository Pattern)


I am using L2S Repository pattern in my ASP.Net 3.5 web app. But I am not quite satisfied with the performance as experienced on the live. I searched google and came across SQL Caching using SqlCacheDependency Class. But i have'nt got any tutorial or link that will explain how to use it in my scenario.

So help me guys...Any help or guidance will be highly appreciated.

Please use some sample codes or online references....

Thanks in Advance

Update: My Repository

public interface IRepository<T> where T : class
{
    T GetById(int id);
    IQueryable<T> GetAll();
    void SaveOrUpdate(T entity);
    void DeleteOnSubmit(T entity);
}

Solution

  • Sometimes linq-to-sql makes queries in unexpected ways. Did you check how your linq queries are translated into sql? Use Sql Server Profiler (available on the tools menu in SQL Management server) to check the queries generated. I wrote some info about it here.

    Once you know that you have good queries generated, you should look if the execution of anyone of them is a performance bottleneck. The profiler can help here too. If some queries are running slow, try to add appropriate indexes.

    Unless you have a very high-volume site, these steps should give you good performance without having to do caching.