Following on from this previous question:
WPF needs ObservableCollection to bind the data. I know I can create the ObservableCollection by using a list in the constructor like:
new ObservableCollection(myListName)
But will the nested groups bind to the WPF form or do I need to run the result of my linq query into a pre-defined type with ObservableCollections at each level?
You can use directly
ObservableCollection<School>andObservableCollection<Class>instead ofIList<School>andIList<Class>in your model classes. This way you ensure that Entity Framework will materialize the collection asObservableCollection<T>when you use eager or lazy loading. WithIList<T>EF would create aList<T>as the concrete type and not anObservableCollection<T>.If your navigation properties are marked as
virtualyou are using lazy loading which means that EF will load the collections automatically as soon as your WPF form wants to access the properties. (The context must not be disposed to get this working.)If you want to load all collections at once in one query you can use eager loading:
This blog post might be helpful as well.