开发者

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

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 dis开发者_Go百科play 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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜