Pergunta

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);
}
Foi útil?

Solução

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.

Outras dicas

You didn't describe how you're using linq to sql with your repository. Basically, are you reusing the same DataContext for all repositories created during a single request, or does each repository get its own DataContext instance? If it's the latter, you lose out on the DataContext's internal cachability.

Another area where performance can be improved is if you have any frequently used queries that contain lots of layers of joins(not just a single table select). Using a CompiledQuery here will speed things up drastically. CompiledQueries only have to be generated the first time they're used, otherwise a query's recompiled each time it's used.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top