I am learning MVVM
. I know model is about my data conceptually. Here is my scenario.
database table definition
create table people (SSN varchar(
Model's are supposed to be dumb data objects that only exist to hold data, so I would not add any kind of data access to that layer.
ViewModels are meant to model the view, and typically would include loading the correct data models for the View to use, however they don't necessarily have to contain the data access code itself.
In most cases, I find it easiest if I put my data access is another layer altogether, and have the ViewModel get the data by interacting with the data access layer.
For example, my ViewModel might have a SearchCommand
that when clicked would do something like this:
void Search(string ssn)
{
PeopleCollection = PeopleRepository.GetPeopleBySsn(ssn);
}
Having a separate layer for data access makes it easier to reuse the data access components, and make the application easier to maintain, update, and test.