Sean Dooley
Sean Dooley

Reputation: 625

MVC Repository project setup

I could do with some guidance about how to setup the MVC Repositories with the following scenario.

Below is a sample of the main tables in my project.

Entity

Tag

Article

Person

Job

Post

With the above information in mind, should I be looking to create a Repository

Entity Repository

Article

Person

Job

Post

I'm using PetaPoco as my ORM. Is this a suitable approach?

Upvotes: 0

Views: 78

Answers (1)

Chris Pratt
Chris Pratt

Reputation: 239290

Well, yes and no. Yes, typically, a repository is for one "thing", so each entity would need it's own repository. However, if you're using Entity Framework or another ORM, then implementing the repository pattern on top of it is a hugely bad idea. The entire purpose of an ORM is to give you repositories. In the case of Entity Framework, each DbSet is a repository and your DbContext is your Unit of Work. Adding another layer on top of this will see you merely proxying one method call to another method call on your context, providing no benefit, and increasing the complexity and maintenance costs of your application.

Either just use your ORM directly, or if you want to abstract it, use a service pattern and create endpoints that satisfy specific queries you will need in your application. Depending on the size of your application, you might only need one service, rather than one per type.

Upvotes: 1

Related Questions