locked
MVC linq to sql repository and search RRS feed

  • Question

  • User1793880005 posted

    I need some guidance for an application I am working on. I have searched the web and the forum and found parts that answer my questions but I want to do this correctly.

    My solution uses LINQ to SQL to model the db and I have a repository that is querying my db everytime a controller needs to get some data for the view.

    I am initially anticipating a maximum of only about a few hundreds hits per day (if that).

    The website is a directory, with listings and requires a search functionality.

    My question is:

    1. What options should I consider to avoid having my repository query the db everytime and is there a tutorial that could help me?

    2. The site contains a 'search' option, how can I implement this against my repository?

    I guess I'm really looking for someone to point me in the right direction.

    So far I've looked at 'caching' the LINQ to SQL model and Lucene.NET but both seem overkill or am I missing the point?

    Hope someone can help!

    Thanks in advance.

    Thursday, April 15, 2010 12:37 PM

Answers

  • User197322208 posted

    What options should I consider to avoid having my repository query the db everytime and is there a tutorial that could help me?

    For caching in ASP.NET, search for "Application" or "Caching" or "Seing objectssion"

    For caching in Business Layer, see

    http://blogs.msdn.com/velocity/archive/2009/03/02/how-to-use-c-to-perform-cluster-administration-in-velocity.aspx

    2. The site contains a 'search' option, how can I implement this against my repository?

    Put a search method in your repository. You must account for pagination (retrieving only 10 or 20 results once)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 15, 2010 3:07 PM

All replies

  • User197322208 posted

    What options should I consider to avoid having my repository query the db everytime and is there a tutorial that could help me?

    For caching in ASP.NET, search for "Application" or "Caching" or "Seing objectssion"

    For caching in Business Layer, see

    http://blogs.msdn.com/velocity/archive/2009/03/02/how-to-use-c-to-perform-cluster-administration-in-velocity.aspx

    2. The site contains a 'search' option, how can I implement this against my repository?

    Put a search method in your repository. You must account for pagination (retrieving only 10 or 20 results once)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 15, 2010 3:07 PM
  • User1793880005 posted

    Hi ignatandrei,

    Thanks for you help.

    OK so I started to add a search method in my repository, but for some reason my search isn't filtering the results correctly.


    public List<MySummary> SearchAllListings(string company)
            {
                var _current = GetAllListings().AsQueryable();
    
                if (company != string.Empty)
                    _current.Where(c=>c.Title.ToLower() == company.ToLower());           
    
                return _current.ToList();
            }


    So in the example above if I pass in a company name it doesn't select the one company I have available, it still returns all of the listings in GetAllListings which is of IQueryable.

    What am I doing wrong?

    THanks in advance.

    Friday, April 16, 2010 3:36 PM
  • User197322208 posted

    _current = _current.Where(c=>c.Title.ToLower() == company.ToLower());     

    Saturday, April 17, 2010 12:35 AM