MCBrandenburg
MCBrandenburg

Reputation: 72

Using MVC3 With DBML

Right now I am using classes generated in the .dbml file and passing the data to the controller through an implementation of the repository pattern. My question is this, do I need to create classes that are essentially clones of the classes from the .dbml without the linq-to-sql and without certain flags, or the ID to have the proper separation of domain logic?

Upvotes: 0

Views: 719

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039328

The clones you are referring to have a name: view models. And yes, you absolutely should be using view models. They are tailored to the specific requirements of a given view. The controller should then query the repository in order to fetch some domain models (autogenerated Linq-To-Sql class, EF entities, ...) and map them to a view model class which will be passed to the view. That's how IMHO every properly architected ASP.NET MVC application should be designed. You should not pass domain models to a view, nor receive any domain models as action parameters from a view. Only view models.

View models are not clones of a domain model. A view model could be mapped out from multiple domain models, or one domain model might break into multiple view models. This way the views have the full flexibility to represent the data independently of the way this data has been transported in the business layers.

Upvotes: 4

Related Questions