Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

72%
+6 −1
Q&A How to separate DB query logic from the application other than implementing a repository on top of an ORM?

I've been doing a lot of reading on implementing the repository pattern in C# projects and found controversy, or shall I say some strong criticism, made by seemingly very smart people with previous...

1 answer  ·  posted 3y ago by Marc.2377‭  ·  last activity 3y ago by Alexei‭

#3: Post edited by user avatar Marc.2377‭ · 2021-02-04T05:31:00Z (about 3 years ago)
  • I've been doing a lot of reading on implementing the repository pattern in C# projects and found controversy, or shall I say some strong criticism, made by seemingly very smart people with previous experience with the pattern, saying that one is better off not implementing a repository on top of an ORM like _Entity Framework Core_.
  • The argument made is that EF Core is already a repository implementation, with the `Context` being the unit of work and each `DbSet` being a repository. _(I don't normally do unit testing so whatever point made about that is irrelevant to me.)_
  • p.s. I'm not sure whether the criticism applies only to generic repositories or not.
  • The thing is, I'm failing to see a sound alternative to separate data access code from my Application layer (business logic implementation). The suggestions I found include consuming the ORM directly from the Application layer, or doing CQRS, or even moving to a microservices architecture. The latter two I'm not interested in; the first doesn't give me the flexibility of implementing my business logic without polluting it with query logic, particularly considering that more than one database will most likely be required in this application.
  • Here's how I want my architecture to look like:
  • ![Architecture diagram](https://software.codidact.com/uploads/eRdSSbQkKyf7bs2xht8qBKyL)
  • _(n.b. I haven't decided about using ViewModels/DTOs for the WebApp and WebAPI instead of referencing Domain models, yet)_
  • For those familiar with the criticism/argument I mention, I'd like to ask how else can one achieve proper separation of concerns in my proposed architecture? Or, in other words, is there a better alternative to implementing the Data Persistence layer other than via the repository pattern?
  • _Fun fact: This is the architecture I was planning (and started implementing) for the Codidact Core software about a year ago, before my hiatus._
  • Thank you!
  • I've been doing a lot of reading on implementing the repository pattern in C# projects and found controversy, or shall I say some strong criticism, made by seemingly very smart people with previous experience with the pattern, saying that one is better off not implementing a repository on top of an ORM like _Entity Framework Core_.
  • The argument made is that EF Core is already a repository implementation, with the `Context` being the unit of work and each `DbSet` being a repository. _(I don't normally do unit testing so whatever point made about that is irrelevant to me.)_
  • p.s. I'm not sure whether the criticism applies only to generic repositories or not.
  • The thing is, I'm failing to see a sound alternative to separate data access code from my Application layer (business logic implementation). The suggestions I found include consuming the ORM directly from the Application layer, or doing CQRS, or even moving to a microservices architecture. The latter two I'm not interested in; the first doesn't give me the flexibility of implementing my business logic without polluting it with query logic, particularly considering that more than one database will most likely be required in this application.
  • Here's how I want my architecture to look like:
  • ![Architecture diagram](https://software.codidact.com/uploads/eRdSSbQkKyf7bs2xht8qBKyL)
  • _(n.b. I haven't decided about using ViewModels/DTOs for the WebApp and WebAPI instead of referencing Domain models, yet.)_
  • For those familiar with the criticism/argument I mention, I'd like to ask how else can one achieve proper separation of concerns in my proposed architecture? Or, in other words, is there a better alternative to implementing the Data Persistence layer other than via the repository pattern?
  • _Fun fact: This is the architecture I was planning (and started implementing) for the Codidact Core software about a year ago, before my hiatus._
  • Thank you!
#2: Post edited by user avatar Marc.2377‭ · 2021-02-04T01:21:52Z (about 3 years ago)
  • I've been doing a lot of reading on implementing the repository pattern in C# projects and found controversy, or shall I say some strong criticism, made by seemingly very smart people with previous experience with the pattern, saying that one is better off not implementing a repository on top of an ORM like _Entity Framework Core_.
  • The argument made is that EF Core is already a repository implementation, with the `Context` being the unit of work and each `DbSet` being a repository. _(I don't normally do unit testing so whatever point made about that is irrelevant to me.)_
  • p.s. I'm not sure whether the criticism applies only to generic repositories or not.
  • The thing is, I'm failing to see a sound alternative to separate data access code from my Application layer (business logic implementation). The suggestions I found include consuming the ORM directly from the Application layer, or doing CQRS, or even moving to a microservices architecture. The latter two I'm not interested in; the first doesn't give me the flexibility of implementing my business logic without polluting it with query logic, particularly considering that more than one database will most likely be required in this application.
  • Here's how I want my architecture to look like:
  • ![Architecture diagram](https://software.codidact.com/uploads/eRdSSbQkKyf7bs2xht8qBKyL)
  • For those familiar with the criticism/argument I mention, I'd like to ask how else can one achieve proper separation of concerns in my proposed architecture? Or, in other words, is there a better alternative to implementing the Data Persistence layer other than via the repository pattern?
  • _Fun fact: This is the architecture I was planning (and started implementing) for the Codidact Core software about a year ago, before my hiatus._
  • Thank you!
  • I've been doing a lot of reading on implementing the repository pattern in C# projects and found controversy, or shall I say some strong criticism, made by seemingly very smart people with previous experience with the pattern, saying that one is better off not implementing a repository on top of an ORM like _Entity Framework Core_.
  • The argument made is that EF Core is already a repository implementation, with the `Context` being the unit of work and each `DbSet` being a repository. _(I don't normally do unit testing so whatever point made about that is irrelevant to me.)_
  • p.s. I'm not sure whether the criticism applies only to generic repositories or not.
  • The thing is, I'm failing to see a sound alternative to separate data access code from my Application layer (business logic implementation). The suggestions I found include consuming the ORM directly from the Application layer, or doing CQRS, or even moving to a microservices architecture. The latter two I'm not interested in; the first doesn't give me the flexibility of implementing my business logic without polluting it with query logic, particularly considering that more than one database will most likely be required in this application.
  • Here's how I want my architecture to look like:
  • ![Architecture diagram](https://software.codidact.com/uploads/eRdSSbQkKyf7bs2xht8qBKyL)
  • _(n.b. I haven't decided about using ViewModels/DTOs for the WebApp and WebAPI instead of referencing Domain models, yet)_
  • For those familiar with the criticism/argument I mention, I'd like to ask how else can one achieve proper separation of concerns in my proposed architecture? Or, in other words, is there a better alternative to implementing the Data Persistence layer other than via the repository pattern?
  • _Fun fact: This is the architecture I was planning (and started implementing) for the Codidact Core software about a year ago, before my hiatus._
  • Thank you!
#1: Initial revision by user avatar Marc.2377‭ · 2021-02-04T01:06:54Z (about 3 years ago)
How to separate DB query logic from the application other than implementing a repository on top of an ORM?
I've been doing a lot of reading on implementing the repository pattern in C# projects and found controversy, or shall I say some strong criticism, made by seemingly very smart people with previous experience with the pattern, saying that one is better off not implementing a repository on top of an ORM like _Entity Framework Core_.  
The argument made is that EF Core is already a repository implementation, with the `Context` being the unit of work and each `DbSet` being a repository. _(I don't normally do unit testing so whatever point made about that is irrelevant to me.)_

p.s. I'm not sure whether the criticism applies only to generic repositories or not.

The thing is, I'm failing to see a sound alternative to separate data access code from my Application layer (business logic implementation). The suggestions I found include consuming the ORM directly from the Application layer, or doing CQRS, or even moving to a microservices architecture. The latter two I'm not interested in; the first doesn't give me the flexibility of implementing my business logic without polluting it with query logic, particularly considering that more than one database will most likely be required in this application.

Here's how I want my architecture to look like:

![Architecture diagram](https://software.codidact.com/uploads/eRdSSbQkKyf7bs2xht8qBKyL)

For those familiar with the criticism/argument I mention, I'd like to ask how else can one achieve proper separation of concerns in my proposed architecture? Or, in other words, is there a better alternative to implementing the Data Persistence layer other than via the repository pattern?

_Fun fact: This is the architecture I was planning (and started implementing) for the Codidact Core software about a year ago, before my hiatus._

Thank you!