I have questions about my the structure of my UWP
app (MVVM
). Basically I have these three Models.
public class Country
{
public int Id { get; set; }
public string Name { get; set; }
public List<City> Cities { get; set; }
...
}
public class City
{
public int Id { get; set; }
public string Name { get; set; }
...
}
public class Item
{
public int Id { get; set; }
public Country Co { get; set; }
public City Ci { get; set; }
...
}
I use the classes Country and City to build a hierarchical menu (ListView
) on the apps first start, therefore I parse a XML file with predefined values. My ItemsSource
for the menu control is an ObservableCollection
public ObservableCollection<Country> Countries { get; set; }
The app should store instances of the class Item
in a local SQLite
database, and this leads to my questions. Is it a good idea to store the datasource for the apps main menu in a local database? I would prefer the database over a file, because it's easier to add new entries (Country).
I use the SQLiteNetExtensions
package from NuGet
so I can map relationships in the database. Which relationships (1:1, 1:m,...) fit the datastructure of the models above? Maybe you can give me a hint, I'm not an expert on data modeling.
Thank you!
Where do the changes originate from? Based on that decide, where to store the data.
I would assume the user is adding instances of Item
and you are storing them to the database, which you will have in the local storage.
For Country
and City
items:
As far as relationships go:
[OneToMany]
public List<City> Cities { get; set; }
[ManyToOne]
public Country Co { get; set; }
[ManyToOne]
public City Ci { get; set; }