Answer the question
In order to leave comments, you need to log in
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 = "Иванов Иван Иванович" };
Answer the question
In order to leave comments, you need to log in
The first option, usually for these purposes, the repository pattern is implemented
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.
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 questionAsk a Question
731 491 924 answers to any question