when to use the poco objects for views, and when the custom viewmodel classes

≯℡__Kan透↙ 提交于 2019-12-24 08:25:06

问题


Imagine that we have a poco that maps a table in a db. There are 15 fields in a poco, only 3 fields of 15 require the view. View display a list of records from db. Can I pass to the view list of poco's objects or I must to create a specific viewmodel class, init it and then pass to the view? I prefer the second variant, but is it good?

Thanks.


回答1:


Your inclination to the second approach is well founded. Creating and using viewmodels is the typical way for displaying data on View.

In short, the viewmodels will only have the required data for display, nothing more, nothing less.

In addition, by using viewmodels, your views are not tightly coupled to the poco's you mentioned.



来源:https://stackoverflow.com/questions/4345585/when-to-use-the-poco-objects-for-views-and-when-the-custom-viewmodel-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!