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 6881601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:07:42+00:00 2026-05-27T05:07:42+00:00

I am using ASP.NET MVC 3 . I get my view’s data in the

  • 0

I am using ASP.NET MVC 3. I get my view’s data in the following sequence:

Controller -> Service Layer -> Repository

In my repository I have a GetAll method that brings back all the records for a specific object, like Category.

So if I need a list of the all the categories then in my controller I would have something like:

IEnumerable<Category> categories = categoryService.GetAll();

In the service layer I would have something like:

public IEnumerable<Category> GetAll()
{
     return categoryRepository.GetAll();
}

Now this is what I need to know where do I actually start to filter the data? Can it be done anywhere in one of these 3 layers or does it only have to be in the repository layer? Lets say I need all the parent categories. Do I have the .GetAll.Where(x => x.ParentCategoryId == null); in my controller, service layer, or repository layer?

Do I have it like this in my controller:

IEnumerable<Category> categories = categoryService.GetParentCategories();

And in my service layer I can have:

public IEnumerable<Category> GetParentCategories()
{
     return categoryRepository.GetAll.Where(x => x.ParentCategoryId == null);
}

Or does my service layer have to look like this:

public IEnumerable<Category> GetParentCategories()
{
     return categoryRepository.GetParentCategories();
}

And then in my repository layer like this:

public IEnumerable<Category> GetParentCategories()
{
     return GetAll()
          .Where(x => x.ParentCategoryId == null);
}

Please can someone help clarify this confusion that I have. There might be different scenarios. I might bring back all categories that have an active status. I might bring back categories with an inactive status. Then do I need a method for each?

  • 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-05-27T05:07:43+00:00Added an answer on May 27, 2026 at 5:07 am

    You should filter at the closest you can from the data source, otherwise you’ll be retrieving records to upper layers that will just be discarded due to a filtering option. This does not scale well, so you need to expose filtering capabilities at all layers that require it, but make sure that the actual filtering is performed in lowest layer possible, generally it is performed at the database level.

    In the example you posted if use GetAll which return an IEnumerable of all the records and only then apply the filtering you’ll have problems in the future because you’re basically loading an entire table into memory and only then applying a filtering.

    Since you’re using EF you could take advantage of the deferred execution properties of the IQueryable. Check:

    .NET Entity Framework – IEnumerable VS. IQueryable

    Should a Repository return IEnumerable , IQueryable or List?


    Update: Following up on your comment you should also check:

    LINQ to entities vs LINQ to objects – Are they the same?

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

Sidebar

Related Questions

I am using ASP.Net MVC. I have a partial view which has a form
I am using ASP.NET MVC with jQuery. I have the following MVC Action that
Using ASP.NET MVC & Spark, I have a view that is listing a number
I am using asp.net MVC. I have edit page url like {controller}/Edit/2 so on
i am using asp.net mvc 2 here i have a following class Applicant and
Using Asp.net MVC, I have one view that's strongly bind to List , and
Using ASP.NET MVC when trying to get the information stored on my Session[objectName] from
How to get ViewData in loaded page, using Asp.net MVC and javascript ?
Using Entity Framework, I suddenly get this strange error after publishing my asp.net mvc
Using asp.net MVC I'd like to do this inside a view: <%= Html.TextBox(textbox1, null,

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.