Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8463211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:23:56+00:00 2026-06-10T14:23:56+00:00

I am still new in entity framework. So forgive me if question is dummy

  • 0

I am still new in entity framework. So forgive me if question is dummy 🙂
I have a domain class that get’s a list of some data from database:

public IEnumerable<Item> GetItems()
        {
            return context.Items.ToList();
        }

This code return all items from database.
On the site I use paging so I need only 10 items per page.
So I did something like this:

var model = itemsRepository.GetItems().
                    Where(x => x.CategoryId == categoryId).
                    OrderByDescending(x => x.CreatedOnDate).
                    Skip(0).
                    Take(pageSize);

Now as I see what I did here is, I take all items from db and filter them.
Will I get some benefit if I put new method in domain and put the following code in it:

return context.Items.Where(x => x.CategoryId == categoryId).
                    OrderByDescending(x => x.CreatedOnDate).
                    Skip(0).
                    Take(pageSize);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:23:57+00:00Added an answer on June 10, 2026 at 2:23 pm

    Yes. You will get the benefit that your LINQ query in the latter case will get translated to SQL and executed in the database. Therefore, your first example will load the entire table into memory – while the second example will do a much more efficient query in the database.

    Essentially, the .ToList() breaks deferred execution – but it might also make sense for you to return IQueryable<T> rather than IEnumerable<T>, and then working on that in upper layers – depending on your requirements. Also, try reading this question and answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm still new to Core Data, so forgive the question. I'm building an app
I'm using Entity Framework 4 and I have created a UnitOfWork class that creates
I have an Entity Framework POCO class that is generated by a T4 Template.
I have a DataLayer class (LINQ2SQL, not entity framework) that returns rows from the
I'm new to the Entity Framework. I have a SQL Function that returns the
I am new to Entity Framework, and ORM's for that mather. In the project
I have to delete some rows in the database. I'm using Entity Framework 4.3
[ I am new to ADO.NET and the Entity Framework, so forgive me if
still new to XML parsing with the iphone so i have a few questions.
I am still new into Codeigniter framework. Today I read about Database Caching http://codeigniter.com/user_guide/database/caching.html

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.