when to use the poco objects for views, and when t

2019-08-08 08:20发布

问题:

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.