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

  • Home
  • SEARCH
  • 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 8835233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:12:48+00:00 2026-06-14T09:12:48+00:00

I’ve recently started implementing the Repository pattern into my service, and I’ve come across

  • 0

I’ve recently started implementing the Repository pattern into my service, and I’ve come across a small niggle that I’d like suggestions about.

Take the following code, in my service:

[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped)]
public Policy GetPolicyById(int policyId, int historyId)
{
    // Don't do the if not deleted check here, as we can do it on our Controller.
    // This means we can use this function if we have to access the deleted records.
    return _policy.GetByID(policyId, historyId);
}

This function is obviously referenced directly from the service interface, and the .GetByID method is part of my generic repository.

The main question is: what if I want to do a .Where(a => !a.Deleted) on this result set. You can see by my code comment what my general idea of thinking is, but is this the “correct” way of doing it, should it be done at the service level, the Controller (UI) level, or should a function be created within my non-generic repository to allow for this functionality?

** UPDATE **

This is another portion of my code, in my policies repository:

/// <summary>
/// 
/// </summary>
/// <param name="policyId"></param>
/// <param name="historyid"></param>
/// <returns></returns>
public virtual IEnumerable<Policy> GetPolicies(int take, int skip)
{
    var policies = GetPoliciesHistoryGrouped().Take(take).Skip(skip);
    return policies;
}

/// <summary>
/// Returns all non-deleted (bitDelete) policies (in an expression, not comitted via the database), 
/// grouped by the latest history ID.
/// </summary>
/// <returns></returns>
private IEnumerable<Policy> GetPoliciesHistoryGrouped()
{
    // Group and order by history ID.
    var historyIDs = _context.Policies.Where(a => !a.bitDelete)
                     .GroupBy(a => a.intPolicyId).Select(group => new
                     {
                         PolicyID = group.Key,
                         HistoryID = group.Max(a => a.intHistoryID)
                     });
    var query = (from h in historyIDs
                 join p in _context.Policies on new { h.HistoryID, h.PolicyID } equals new { HistoryID = p.intHistoryID, PolicyID = p.intPolicyId }
                 select p).OrderBy(a => a.intPolicyId);
    return query;
}

Should this level of depth should not be in the repository layer, instead be in the service layer, in which the GetPoliciesHistoryGrouped function would still have to be created and shared? Remember, .Take and .Skip cannot be called until after the Grouping has been done.

  • 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-14T09:12:49+00:00Added an answer on June 14, 2026 at 9:12 am

    Your reasoning is correct. This filtering is business logic that should be done in the service layer. The repository contains only simple CRUD methods.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,

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.