Y
Y
Ytsu Ytsuevich2015-03-20 23:04:02
C++ / C#
Ytsu Ytsuevich, 2015-03-20 23:04:02

MVC, Entities. What should the controller "see"?

There are typed classes created by Entity . How should the Controller manipulate them?
1) In the model, you need to create a class (as a wrapper) with methods that will change the data in the database
2) The controller knows about all entity classes and can do this in its methods:

var test = new TestEntity();
test.Human.Add { Name = "Иванов Иван Иванович" };

The question is more philosophical, but I'm waiting for everyone's opinion !!!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
ArturNak, 2015-03-20
@ArturNak

The first option, usually for these purposes, the repository pattern is implemented

S
Sergey Protko, 2015-03-21
Protko @Fesor

We read about the service layer and why controllers should not directly manage business logic.
As for the model, entities should not know anything about who and how stores them where. As already mentioned - the repository template. In C#, there seems to be no problem with normal ORMs.

R
Razaz, 2015-03-22
@Razaz

A few points:
Let's start with the fact that EntityFramework is an ORM that provides an implementation of an abstract repository and a Unit of Work.
Entities can be of three kinds - presentation models, business domain models, and storage layer-specific models.
Using EF means reducing storage tier models to a minimum. If you are making specific models for the storage layer, you don't need EF. Take Dapper the same one.
The repository pattern is recommended for abstracting the data storage layer - that is, you can have an EntityFrameworkRepository, MongoDbRepository, FileRepository. If such abstractions are not needed, then the repository pattern apart from EF is not needed, and moreover, it is an anti-pattern.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question