ViewModels with asp.net mvc 4 and EntityFramework whats the Point

I am discussing with myself, what is the point of creating ViewModel classes in a project that uses the Entity Framework?

I currently have a project that uses EntityFramework. My solution is structured basically like this:

  • User Interface Project (contains controllers and views)
  • Model project (contains EntityFramework model)
  • Services project (contains service classes that talk to Model Project to service objects from a model project in a user interface project).

My controllers pass objects that the Entity Framework creates directly to the view.

It is good and simple.

In the past, I would create separate classes for the view models and map to the objects that EntityFramework creates for these view models. But now I'm trying my best to understand the essence of the matter.

I am currently helping a project that displays objects created by an entity infrastructure to view models. He really uses AutoMapper for this.

Now it all looks like a lot of effort and code for very little gain.

Did I miss something?

+5
source share
3 answers

, - , ORM MVC - , ASP.NET MVC Framework Entity Framework ( .NET...).

: , . , .

1: View ,

"" - MVC , , . : " , , ". MVC, , , , .

, , , ( ) , , ( , , , ). , , , , . , , , , .

2: ORM

ORM - , 1 - , , . , , save() - , . ORM ORM- : ( : ) (, ). , " ", ORM, . - ( ) .

, , ORM. Entity Framework , , , () EF , , Code-First.

: ?

, .. , , , . , ORM " MVC".

: ?

Queti-Mporta , . , , , .

, , . , , , , , .. . - , . , , , .


1 .NET "POCO" " CLR". Java POJO ( Java), , - , .

+13

ViewModels, , . , .

- . Ruby.

+7

I would consider this question. What is a ViewModel in MVC that explains the purpose of a ViewModel.

There is nothing wrong with passing a model directly from your object to a view, but the ViewModel can be used when your model is not an exact match for the data you need.

+2
source

All Articles