C# Entity Framework with ASP.NET MVC Data Access Design Patterns Using the Repository Pattern

Joe Di Trolio
Joe Di Trolio
3,367 Points

Using the Repository Design Pattern for non-crud operations in an MVC application

Firstly, what a fantastic series!

I have a question concerning the Repository Design Pattern in an MVC application.

I understand that using a repository is a great centralised location for storing CRUD operations and interacting with a database.

However, is it considered a good design pattern for the same repository to also contain other kinds of operations - that don’t necessarily interact directly with the database?

For example, in my application, a controller uses a method in my repository to insert new information from a form into a database. However, the information must be manipulated first and that’s handle by a separate method.

FORM -> CONTROLLER -> METHOD 1 (Manipulate data) -> METHOD 2 (Insert data to db)

Where should this intermediary method (Method 1) ideally go in my application?

I hope my question make sense and please hesitate to let me know in case you need some clarification.

1 Answer

Steven Parker
Steven Parker
195,275 Points

Does it manipulate it and insert it? Or just manipulate it and sent it back? In the first case, it would seem entirely appropriate to handle it in the same controller. In the second case you might set up a separate controller, but if you're not doing a lot of that kind of thing you still may just keep it in the same controller for expedience.