开发者

Use of DTO in ASP.NET MVC

In the context of ASP.Net MVC 2开发者_开发问答.0, can anybody please explain why do we need to use DTO (Data Transfer Object) if there can already be Models? I have seen an example where a web service returns DTO to asp.net and then it is converted to Model using some factory class. This web service talks to database and returns data in the form of DTO.

In my previous projects, I used to communicate to DB using Data context and repository, which used to return model object to my controller. Then I used to pass this model to the corresponding view. Isn't this simpler? I cannot find out the exact use of DTO pattren.


Models represent the logical data model that your views are coded against. This may or may not map 1:1 with the source(s) of the data. In a situation where Model == DTO, I agree, the DTO is somewhat redundant.

In most situations where I've used MVC, it's been pretty rare to have a single source of data, or lack the desire to separate the logical view from the physical sources. For example I often make multiple service and database calls to build single logical model.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜