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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:29:04+00:00 2026-06-13T15:29:04+00:00

I currently have a Repository/UnitOfWork pattern down. However, there is one hard coupling that

  • 0

I currently have a Repository/UnitOfWork pattern down. However, there is one hard coupling that I am unable to figure out how I can get rid of.


This is an overview of my pattern:

Business Logic Layer

  • IRepository
    • Used as type contraint
  • IRepository< TModel, TDTO >
    • Implements IRepository
    • General CRUD methods
  • IEmployeeRepository< TModel >
    • Implements IRepository< TModel, EmployeeDTO >
    • Some employee specific methods
  • IUnitOfWork
    • Getter for repositories
    • Save method
  • IEntityWithId
    • Interface to force (and expose) DTOs and EF POCOs to have a Int32 field called ID
    • Used as type contraints
  • EmployeeDTO (Mapped with AutoMapper in the implemented EmployeeRepository)
    • DTO entity used in the core project and (to come) test project

Data Layer (Injected with Ninject)

  • UnitOfWork
    • Implementation of IUnitOfWork based on Entity Framework
  • EmployeesRepository
    • Implementation of IEmployeeRepository< TModel >
  • Employee
    • EF POCO

Core

  • EmployeesController
    • Parametered constructer EmployeesController(IUnitOfWork unitOfWork)
    • IUnitOfWork is injected with a Ninject module as a UnitOfWork (from Data layer)

Those are the problem methods in my generic IRepository interface.

TDTO Find(Expression<Func<TModel, bool>> filter);

and

IEnumerable<TDTO> FindAll(Expression<Func<TModel, bool>> filter);

As you can see, there is TModel in there, which is used to build up an expression to filter results. I COULD do something like using an expression on the DTO, but that would require a complete list of employees mapped to DTOs (aka it wouldnt generate a SQL filter but it would filter a SELECT * FROM Employee result list). So this isn’t a good option.

The other, more viable but not optimal solution is to use dynamic LINQ. That way, I can pass a simple string in the Find / FindAll methods and get rid of the TModel requirement. However, this would means that refactoring becomes annoying since it fills the code with magic strings.

  • 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-13T15:29:06+00:00Added an answer on June 13, 2026 at 3:29 pm

    Just as I posted this, I think I figured out where my problem is.

    Find() and FindAll() shouldn’t even exist. I should write more specific methods like FindEmployeeByName(string name) in the IEmployeeRepository, then implement it like so :

    EmployeeDTO FindEmployeeByName(string name)
    {
        return Mapper.Map<EmployeeDTO>(dbSet.Where(o=>o.name.Contains(name)).FirstOfDefault());
    }
    

    Can anyone confirm this is a proper way to do it? Or suggest something even better?

    Edit

    Also, if I want to keep Find(Expression…) and FindAll(Expression…) methods, I can, but they are just in the Data layer and used by implemented methods to avoid repeated code. But they should not be used in controllers as they requires knowledge of the underlaying data structure, beyond my Business Logic. That said, they can be implemented in a BaseRepository< TModel > (That I already have but did not mention to keep things more simple) and make EmployeesRepository an extention of BaseRepository. That way, every Repository already have those generic-like method that are Model-Aware.

    Not sure if I explained that properly. Let me know if it’s unclear and I’ll try to edit this and make it better.

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

Sidebar

Related Questions

I currently have a complete generic repository but I'm missing one feature and that
Currently have a drop down menu that is activated on a hover (from display:none
I currently have one project that currently contains multiple packages. These packages make up
I currently have a repository setup that loads forms a person would need to
I currently have a SVN repository on a server that is low in available
I currently have a large (30K commits) SVN repository that I am in the
I currently have a git repository that I imported from svn a while ago
I currently have existing Intellij IDEA projects that are tied to the SVN repository.
In my current project we have a large repository of content that was originally
Currently have password protection on my main and sub directories, however I'd like to

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.