K
K
KLUBS2012-07-20 20:48:20
.NET
KLUBS, 2012-07-20 20:48:20

Do I need a layer between the Entity Framework and the site?

Hello!

Help, please, to understand. Do I need an additional layer from the model between the Entity Framework and the controller that works with the data layer. Those. I see 2 options:

1.

There is a dbUsers table in the database. EF creates the dbUsers classes. Somehow the User class is created. The data layer works with EF objects and gives the user (controller) beautiful clean objects of the User class without unnecessary information.

2.
There is a dbUsers table in the database. EF creates the dbUsers classes. The data layer directly works with these objects and passes them to the controller. Those. the controller works with objects of the dbUsers type… Tell me

, how is it correct and why?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
SychevIgor, 2012-07-20
@SychevIgor

From the point of view of architectural concepts and feng shui, there should be some layer just because the controller needs a view model and it is different from what is just a model. an example needs to be done pager ... those we should have a view model with an array of these objects (really, all the same, if the base is large, not quite an array or a list, but oh well) and the page number, and this is already sorry, not that it is stored in the database ...
there is already a web context applications have some about which the database and model data are not required to know
. And from the point of view of rapid development, you can directly do and violate all the concepts of mvc and so on. Well, if you make a simple admin panel on select update delete insert, then there, too, it seems to me that everyone put the bolt on it

G
ganouver, 2012-07-23
@ganouver

Here is the ViewModel and Domain Model: Responsibilities are pretty clear. Advantages and disadvantages of each approach.

F
FanKiLL, 2012-07-26
@FanKiLL

I haven’t written on asp.net mvc for a long time, but at one time I used the ViewModel.
For example, you have a User class that, among other variables, has an active variable that can be true / false, whether you are an active user or not, let's say you have a user registration form, but you do not want to shine this variable. It is not safe to use the User model, since this field can still be filled in and when the form is mapped to the model, this variable will be filled in, there are two solutions.
1)public ActionResult registration([Bind(Exclude = "active")] User model)
So, when mapping form data to a model, the active field will be ignored.
2)public ActionResult registration(UserViewModel model)
The UserViewModel will be exactly the same as the User class, except for the active field, so the active field from the form will never come at all.
I repeat, I have not written on asp.net mvc for a long time, so maybe someone will add or correct something.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question