2

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?

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Jurisdiction is a model class. I'm using the entity framework to provide datadase access, and I didn't want to load the model classes it uses with too many extra methods. Maybe I need to introduce a new layer of classes between the entity framework classes and my viewmodels.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.