Reputation: 11607
I am new to WPF. I'm trying to write a program that makes use of the MVVM design pattern.
My program has a list of countries that are fetched from the database on startup, and are static after that. Where is the place to put these? At the moment, I have them sitting at the top level of my ViewModel class hierarchy:
abstract class AbstractViewModel
{
static Jurisdiction[] jurisdictionOptions;
public Jurisdiction[] JurisdictionOptions
{
get {
if (jurisdictionOptions == null)
{
using (var db = new DatabaseContext())
{
jurisdictionOptions = db.Jurisdictions.ToArray();
}
}
return jurisdictionOptions;
}
}
}
I can then set the ItemSource
of UIElements to JurisdictionOptions
.
Is this the correct way of implenting this?
Upvotes: 2
Views: 307
Reputation: 11906
If you are implementing the MVVM pattern you should also have a model class.
In general you should put your database code inside the model.
Upvotes: 4