none
Which statement is better for performance. RRS feed

  • Question

  • using (Entities entity = new Entities()) { List[] dbLists; DbQuery<List> lists = entity.Lists.Include("Page"); int _pageid = Convert.ToInt32(pageid); dbLists = lists.Where(p => p.PageId == _pageid).ToArray(); return View(dbLists); } using (Entities entity = new Entities()) { List[] dbLists; int _pageid = Convert.ToInt32(pageid); dbLists = entity.Lists.Include("Page").Where(p => p.PageId == _pageid).ToArray(); return View(dbLists); }

    Hi. I have these two entity queries and I want to know which one is better for performance? If one of them is better than the other please can someone explain why it is better for performance or can provide me a link to get the idea.

    • Edited by Blast4620 Sunday, August 31, 2014 9:31 AM
    Sunday, August 31, 2014 9:26 AM

Answers

  • The second one as it will generate a T-SQL query with a WHERE clause and thus not select all records from the Lists/Page tables.

    The first approach does the filtering in memory after you have fetched all records from the database.
    The second approach does the filtering directly on the database side and won't fetch more records than necassary.

    • Marked as answer by Blast4620 Sunday, August 31, 2014 9:49 AM
    Sunday, August 31, 2014 9:42 AM