Questions tagged [repository-pattern]

The repository pattern provides a way to provide isolation between the data access layer of your application with the business layer. When using this tag on implementation heavy questions - tag the code language the implementation is written in.

Filter by
Sorted by
Tagged with
602 votes
11 answers
202k views

What's an Aggregate Root?

I'm trying to get my head around how to properly use the repository pattern. The central concept of an Aggregate Root keeps coming up. When searching both the web and Stack Overflow for help with what ...
Dinah's user avatar
  • 53.5k
570 votes
14 answers
247k views

What is the difference between DAO and Repository patterns?

What is the difference between Data Access Objects (DAO) and Repository patterns? I am developing an application using Enterprise Java Beans (EJB3), Hibernate ORM as infrastructure, and Domain-Driven ...
Thurein's user avatar
  • 6,725
341 votes
11 answers
92k views

Proper Repository Pattern Design in PHP?

Preface: I'm attempting to use the repository pattern in an MVC architecture with relational databases. I've recently started learning TDD in PHP, and I'm realizing that my database is coupled much ...
Jonathan's user avatar
  • 18.7k
238 votes
13 answers
52k views

DDD - the rule that Entities can't access Repositories directly

In Domain Driven Design, there seems to be lots of agreement that Entities should not access Repositories directly. Did this come from Eric Evans Domain Driven Design book, or did it come from ...
codeulike's user avatar
  • 22.9k
236 votes
5 answers
135k views

Difference between Repository and Service Layer?

In OOP Design Patterns, what is the difference between the Repository Pattern and a Service Layer? I am working on an ASP.NET MVC 3 app, and am trying to understand these design patterns, but my ...
Sam's user avatar
  • 15.6k
168 votes
1 answer
48k views

How are Spring Data repositories actually implemented?

I have been working with Spring Data JPA repository in my project for some time and I know the below points: In the repository interfaces, we can add the methods like findByCustomerNameAndPhone() (...
Vasu's user avatar
  • 22.1k
161 votes
1 answer
68k views

Difference between a Factory, Provider and a Service?

What is the difference between the terms Factory, Provider and Service? Just getting into NHibernate and its Repository pattern (POCO classes, etc).
mrblah's user avatar
  • 102k
144 votes
3 answers
29k views

Generic Repository With EF 4.1 what is the point

As i dig deeper in to the DbContext, DbSet and associated interfaces, I am wondering why you would need to implement a separate "Generic" Repository around these implementations? It looks like ...
Code Jammr's user avatar
  • 1,867
134 votes
4 answers
44k views

Managing relationships in Laravel, adhering to the repository pattern

While creating an app in Laravel 4 after reading T. Otwell's book on good design patterns in Laravel I found myself creating repositories for every table on the application. I ended up with the ...
ehp's user avatar
  • 1,699
104 votes
9 answers
33k views

NOT using repository pattern, use the ORM as is (EF)

I always used Repository pattern but for my latest project I wanted to see if I could perfect the use of it and my implementation of “Unit Of Work”. The more I started digging I started asking myself ...
Dejan.S's user avatar
  • 18.9k
96 votes
4 answers
28k views

Well designed query commands and/or specifications

I've been searching for quite some time for a good solution to the problems presented by the typical Repository pattern (growing list of methods for specialized queries, etc.. see: http://ayende.com/...
Erik Funkenbusch's user avatar
91 votes
1 answer
95k views

Method cannot be translated into a store expression

I saw this code work with LINQ to SQL but when I use Entity Framework, it throws this error: LINQ to Entities does not recognize the method 'System.Linq.IQueryable'1[MyProject.Models....
Shawn Mclean's user avatar
  • 57.1k
90 votes
7 answers
20k views

How can I use the repository pattern correctly?

I am wondering how should I be grouping my repositories? Like from the examples I seen on the ASP.NET MVC and in my books they basically use one repository per database table. But that seems like a ...
chobo2's user avatar
  • 84.4k
88 votes
4 answers
78k views

EF Including Other Entities (Generic Repository pattern)

I am using the Generic Repository pattern on top of Entity Framework Code First. Everything was working fine until I needed to include more entities in a query. I got to include one entity ...
Kassem's user avatar
  • 8,206
88 votes
1 answer
81k views

Repository Pattern - How to understand it and how does it work with "complex" entities?

I'm having a hard time understanding the Repository Pattern. There are a lot of opinions on that topic like in Repository pattern done right but also other stuff like Repository is the new Singleton ...
Stefan Falk's user avatar
  • 24.7k
85 votes
4 answers
35k views

DDD - Persistence Model and Domain Model

I am trying to learn domain-driven design (DDD), and I think I got the basic idea. But there is something confusing me. In DDD, are the persistence model and domain model different things? I mean, we ...
ayk's user avatar
  • 1,477
84 votes
8 answers
84k views

How can I implement the Unit Of Work pattern with Dapper?

Currently, I am trying to use the Dapper ORM with the Unit Of Work + Repository Pattern. I want to use Unit of Work as opposed to a simple Dapper repository due to the fact that my insert and updates ...
Stig's user avatar
  • 1,249
79 votes
15 answers
142k views

Laravel 5 - Interface is not instantiable [duplicate]

I know that this question was asked so many times, but none of answers helped me. I'm getting exception in Laravel 5 BindingResolutionException in Container.php line 785: Target [App\Contracts\...
Andrew Kulakov's user avatar
71 votes
10 answers
77k views

An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key

Using EF5 with a generic Repository Pattern and ninject for dependency injenction and running into an issue when trying to update an entity to the database utilizing stored procs with my edmx. my ...
Juan's user avatar
  • 1,144
67 votes
8 answers
55k views

Why use Repository Pattern or please explain it to me?

I am learning repository pattern and was reading Repository Pattern with Entity Framework 4.1 and Code First and Generic Repository Pattern - Entity Framework, ASP.NET MVC and Unit Testing Triangle ...
King Chan's user avatar
  • 4,272
64 votes
4 answers
46k views

Best Repository Pattern for ASP.NET MVC

I recently learned ASP.NET MVC (I love it). I'm working with a company that uses dependency injection to load a Repository instance in each request, and I'm familiar with using that repository. But ...
Jonathan Wood's user avatar
63 votes
8 answers
52k views

Unit of Work + Repository Pattern: The Fall of the Business Transaction Concept

Combining the unit of work (UoW) and repository pattern is something used fairly widely nowadays. As Martin Fowler says, a purpose of using UoW is to form a business transaction while being ignorant ...
Alireza's user avatar
  • 10.3k
60 votes
7 answers
31k views

Transactions in the Repository Pattern

How do I encapsulate the saving of more than one entity in a transactional manner using the repository pattern? For example, what if I wanted to add an order and update the customer status based on ...
Charles Graham's user avatar
58 votes
5 answers
7k views

Repository pattern vs. "smart" business objects [closed]

I see two main "schools of thoughts" when it comes to creating larger-scale enterprise-wide apps on .NET (Winforms, WPF, ASP.NET). Some folks use the "repository pattern" which uses a repository that ...
56 votes
3 answers
28k views

Having a repository dependent on another repository

I've recently been spending time reading up on SOLID principles and decided to seeing how the code base I work with compares. In some of our code there is a repository (repository A). When a record ...
MrGrumpy's user avatar
  • 593
54 votes
2 answers
25k views

Repository pattern - Why exactly do we need Interfaces?

I have read from internet I got this points which says Interfaces is used for this Use TDD methods Replace persistance engine But I'm not able to understand how interface will be usefull to this ...
Meson's user avatar
  • 869
54 votes
6 answers
51k views

Repository pattern and mapping between domain models and Entity Framework

My repositories deal with and provide persistence for a rich domain model. I do not want to expose the anemic, Entity Framework data entity to my business layers, so I need some way of mapping ...
Dave New's user avatar
  • 39.4k
54 votes
3 answers
14k views

How does a service layer fit into my repository implementation?

I have created a POCO model class and a repository class which handles persistence. Since the POCO cannot access the repository, there are lots of business logic tasks in the repository which doesn't ...
jpshook's user avatar
  • 4,924
52 votes
2 answers
22k views

What exactly is the difference between a data mapper and a repository?

Well I've been trying to find out the difference between data mapper and repository, but up to now I still have not. It seems to me that the expert programmer said "Repository is another layer of ...
Lord Yggdrasill's user avatar
51 votes
7 answers
37k views

Entity Framework 6 Code First - Is Repository Implementation a Good One?

I am about to implement an Entity Framework 6 design with a repository and unit of work. There are so many articles around and I'm not sure what the best advice is: For example I realy like the ...
davy's user avatar
  • 4,512
50 votes
2 answers
23k views

Repository Pattern - Caching

I'm not sure where I should implement the caching in my repository pattern. Should I implement it in the service-logic or in the repository? GUI -> BusinessLogic (Services) -> DataAccess (...
Beni's user avatar
  • 535
49 votes
7 answers
14k views

What specific issue does the repository pattern solve?

(Note: My question has very similar concerns as the person who asked this question three months ago, but it was never answered.) I recently started working with MVC3 + Entity Framework and I keep ...
Dave's user avatar
  • 1,057
49 votes
13 answers
53k views

It's not possible to lock a mongodb document. What if I need to?

I know that I can't lock a single mongodb document, in fact there is no way to lock a collection either. However, I've got this scenario, where I think I need some way to prevent more than one thread ...
Mathieu Pagé's user avatar
48 votes
4 answers
25k views

How to fake DbContext.Entry method in Entity Framework with repository pattern

Because I want to unit test my code I have implemented the repository pattern in my MVC4 application. I managed to make a Context Interface, a fake Context and use a fake implementation of a System....
user2609980's user avatar
  • 10.4k
48 votes
3 answers
8k views

Service Layers and Repositories

I've been using MVC frameworks for a short while now and I really like how the concerns are separated out. I've got into a bad habit of letting the controllers do quite a bit of work. So I'm really ...
John Polling's user avatar
  • 2,282
44 votes
5 answers
26k views

Multiple Git repositories for each Eclipse project or one Git repository

I am in the process of moving to Git from SVN. In SVN I had multiple eclipse projects in a single SVN repository that is convenient for browsing projects. I was going to move to having one git ...
Codey McCodeface's user avatar
44 votes
5 answers
45k views

Implementation of Repository Pattern in Python?

Mainly out of curiosity, I'm looking for a Python framework or example for the Repository Pattern of decoupling persistence logic from domain logic. The name "Repository Pattern" appears in the post ...
Graham's user avatar
  • 876
43 votes
6 answers
40k views

Implementing retry logic for deadlock exceptions

I've implemented a generic repository and was wondering if there is a smart way to implement a retry logic in case of a deadlock exception? The approach should be the same for all repository methods. ...
user1638662's user avatar
43 votes
3 answers
17k views

LINQ to SQL and the repository pattern

I feel like I'm running around in circles. I can't seem to make up my mind as to what the right repository pattern is using LINQ to SQL. If you're familiar with Rob Conery's MVC Storefront you will ...
Micah's user avatar
  • 114k
43 votes
3 answers
24k views

Generate POCO classes in different project to the project with Entity Framework model

I'm trying to use the Repository Pattern with EF4 using VS2010. To this end I am using POCO code generation by right clicking on the entity model designer and clicking Add code generation item. I ...
Max's user avatar
  • 1,553
43 votes
4 answers
12k views

Repository Pattern: how to Lazy Load? or, Should I split this Aggregate?

I have a domain model that has the concept of an Editor and a Project. An Editor owns a number of Projects, and a Project has not only an Editor owner, but also a number of Editor members. Therefore,...
Giraffe's user avatar
  • 2,013
42 votes
3 answers
38k views

How to get primary key value with Entity Framework Core

We are currently using the method below which depends upon IObjectContextAdapter in an abstract Repository. From what I'm reading, it appears that anything related to ObjectContext is being chopped ...
cResults's user avatar
  • 763
41 votes
5 answers
36k views

Repository and Unit of Work patterns - How to save changes

I'm struggling to understand the relationship between the Repository and Unit of Work patterns despite this kind of question being asked so many times. Essentially I still don't understand which part ...
Peter Monks's user avatar
  • 4,309
39 votes
7 answers
12k views

Best way to implement Repository Pattern?

I've been exploring BDD/DDD and as a consequence trying to come up with a proper implementation of the Repository pattern. So far, it's been hard to find a consensus over the best way to implement ...
Michael Cook's user avatar
  • 1,686
39 votes
4 answers
19k views

Specification Pattern in Domain Driven Design

I've been struggling around a DDD-related issue with Specifications and I've read much into DDD and specifications and repositories. However, there is an issue if trying to combine all 3 of these ...
Tseng's user avatar
  • 62.8k
37 votes
8 answers
21k views

Replacing a full ORM (JPA/Hibernate) by a lighter solution : Recommended patterns for load/save?

I'm developing a new Java web application and I'm exploring new ways (new for me!) to persist the data. I mostly have experience with JPA & Hibernate but, except for simple cases, I think this ...
electrotype's user avatar
  • 8,566
37 votes
6 answers
51k views

Configuring Ninject with Asp.Net MVC & Web Api

i have setup my project with Ninject IoC. My project has regular Asp.Net MVC controllers and Web Api controllers. Now, Ninject works with Web Api but Ninject doesn't work with regular Asp.MVC ...
Idrees Khan's user avatar
  • 7,722
37 votes
6 answers
118k views

using stored procedure in entity framework

I am using asp.net mvc 5 and C# with Entity Framework... I have model and domain classes for function... now I need to use stored procedure.... which I am struggling at the movement. I am following ...
K.Z's user avatar
  • 5,423
37 votes
7 answers
17k views

Repository Pattern Standardization of methods

All I am trying to find out the correct definition of the repository pattern. My original understanding was this (extremely dumbed down) Separate your Business Objects from your Data Objects ...
Nix's user avatar
  • 57.7k
36 votes
12 answers
231k views

Error while validating the service descriptor 'ServiceType: INewsRepository Lifetime: Singleton ImplementationType: NewsRepository':

I try get data from my database with repository Pattern i have 3 project Bmu.Mode 'this is for model to create database' Bmu.Repo 'it have 2 folder for repository include contract/...
sunny's user avatar
  • 2,699

1
2 3 4 5
64