DTO =视图模型? [英] DTO = ViewModel?

查看:880
本文介绍了DTO =视图模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用NHibernate坚持我的域对象。
为了简单起见,我使用的是ASP.NET MVC项目既是我的presentation层,我的服务层。

I'm using NHibernate to persist my domain objects. To keep things simple I'm using an ASP.NET MVC project as both my presentation layer, and my service layer.

我想从我的控制器类XML返回我的域对象。在这里阅读一些职位对堆栈溢出后,我收集的DTO是要走的路。不过,我也碰到过帖子谈论的视图模型。

I want to return my domain objects in XML from my controller classes. After reading some posts here on Stack Overflow I gather DTOs are the way to go. However, I've also come across posts talking about the ViewModel.

我的问题:是数据传输对象和的ViewModels是一回事吗?或者是一个ViewModel有种DTO?

My question: Are Data Transfer Objects and ViewModels the same thing? Or is a ViewModel a kind of sub pattern of a DTO?

推荐答案

一个DTO的规范定义是一个对象,没有任何行为数据的形状。

The canonical definition of a DTO is the data shape of an object without any behavior.

的ViewModels是视图的模型。的ViewModels通常是从特定视图的行为的一个或多个对象(或DTO的)加上任何附加的部件的全部或部分数据(可由视图执行方法,属性,以指示视图如何切换元件等)。你可以看一下视图模型作为一个视图以及行为的所有数据。的ViewModels可以或可以不映射一对一到业务对象或DTO的

ViewModels are the model of the view. ViewModels typically are full or partial data from one or more objects (or DTOs) plus any additional members specific to the view's behavior (methods that can be executed by the view, properties to indicate how toggle view elements etc...). You can look at the viewmodel as all the data for a view plus behaviors. ViewModels may or may not map one to one to business objects or DTOs.

顺便说一句,NHibernate的预测派上用场,如果某个视图模型的需求该数据从持久对象的一个​​子集。

By the way, NHibernate projections come in handy if a certain viewmodel needs a subset of the data from a persisted object.

这篇关于DTO =视图模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆