Base solution for your next web application
Open Closed

Performance Question regarding GetAll #362

relix3000 created

Hi! I have a simple question regarding performance as I've seen this situtation happen before and just wanted to make sure. When we use GetAll, from IRepository, and then filter results... is the whole table fetched from the table and then filtered or is it filtered before fetching to database? Thanks in advance.

3 Answer(s)
  • 0
    terrybentley created

    I had a look at the sql generated using SQL Profiler and in both the following cases the WHERE clause was added limiting the rows fetched from the table.

    _myRepository .GetAll() .Where(e => e.AssetId == input.AssetId && e.StartTime >= input.StartTime) .WhereIf(input.EndTime.HasValue, e => e.EndTime <= input.EndTime)

    _myRepository .GetAllList((a => a.Core.IsActive == true && a.Core.ApplicationId == input.ApplicationId));

  • 0
    relix3000 created

    Thanks Terry. My SQL profiler has been giving me trouble and I couldn't find any way to see how it was working underneath. Thanks a lot!

  • 0
    ddnils created

    Hi there, since GetAll() returns a Queryable, this indicates it filters on database. Since the SQL Query is not called yet and still in production. It will first be evaluated, when you call .ToList() or iterate manually over it. On the other hand: Thanks for evaluating this again :)