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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:08:40+00:00 2026-06-10T07:08:40+00:00

I have created a generic unit of work/repository pattern and it works in most

  • 0

I have created a generic unit of work/repository pattern and it works in most cases.

Here’s an example:

public IEnumerable<Deal> GetBySubcategory(int subcategoryId)
{
    using (var uow = new ReadUow())
    {
        var r = new ReadRepo<Deal>(uow.Context);

        var deals = r.FindBy(d => d.DealSubcategories.Any(s => s.SubcategoryId == subcategoryId))
            .Include("DealSubcategories");

        return deals.ToList();
    }
}

In order to keep the size of data to a minimum, I try to filter each main query. The question I have is, how to make the above more reusable?

The above method has one filter, but this could be 2, 3 or more. If possible I don’t want to create a method for each variation but as soon as the IEnumerable<T> exits the context, it’s no longer avaiable without calling ToList() or something. This means that everything at that point is materialized, even though it may not be used and can only impact performance.

Anyone got any experience of extending this context as I’ve described?

  • 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-10T07:08:41+00:00Added an answer on June 10, 2026 at 7:08 am

    Instead of returning IEnumerable<T>, return IQueryable<T>, by omitting the .ToList()in your return statement.

    However your DbContext would need to live throughout the length of the HttpRequest (assuming it’s a website).


    A while ago, I’ve made a blog post, somewhat related to this (I think).

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

Sidebar

Related Questions

I am utilizing the Unit Of Work and Generic Repository pattern in my MVC
I have a class User. I have created a generic CSV exporter that works
Cheers!I have some doubts about using Unit of Work with Repository. Specially a role
I have been using http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application as guidance to help me create a repository.I have
I am trying to create a generic formatter/parser combination. Example scenario: I have a
I have created two imageViews promatically as shown below: public void createImageViews(Integer count){ ImageView[]
I have created a generic method that enables clients to specify both the concrete
I have created an instance of a generic collection in C#, and need to
I have created a subclass of a generic list so that I could implement
I have created a Generic Extension method for DataRow object. The method takes no

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.