Place where methods of interaction of CRUD with the bank in ASP.NET MVC should be

Asked

Viewed 278 times

0

I am using the Entity framework and developing a system through ASP.NET MVC5 but I was in doubt about CRUD.

The methods of interaction with the database (Create,Update,Select,Delete) should be inserted in which part of the project? I thought about describing each of these functions within the Model classes, but it doesn’t seem right.

Another question... the right one is to create a generic CRUD interface for all models?

  • Look, Cleiton, I’m gonna put this in for comment because I don’t know if that’s a good answer. But, this interaction with the bank can be done in a class in a directory within the same project. This would be the famous DAO - Data Access Object. That would be the generic repository of your project. And regarding the second doubt, I think yes, can create a generic for all models. But I’m not sure about that.

  • @Érikthiago Cara, please, forgets generic repository. I’ve written several responses telling you not to use this approach.

1 answer

2

The methods of interaction with the database (Create, Update, Select, Delete) should be inserted in which part of the project? I thought about describing each of these functions within the Model classes, but it doesn’t seem right.

Totally incorrect, especially because it is using the Entity Framework, which already implements a repository and makes this work unnecessary.

I defend this in these two answers:

The Model is the class that represents the data within your application, and that alone.

Another question... the right one is to create a generic CRUD interface for all models?

Wrong. The right thing is for you to use the technique of Scaffolding, that generates a Controller for you with CRUD operations implemented by Action. Look at this other answer where I detain it better.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.