Hi I am designing an application using WPF, EF and MVVM (.NET4.0).
I face issue with freezing UI when I’m binding data. I think this is because of lazy loading.
MVVM:
ThreadPool.QueueUserWorkItem(state =>
{
IsProgressBarVisible(true);
var service = Context.SomeModel.ToList();
BgServiceCompleted(service);
});
XAML:
"{Binding OrderItemViews.SOmeModel_A.SomeModel_B.SOmeField}"
"{Binding OrderItemViews.Country.Name}"
Some Model:
public class SomeModel_A
{
public int Id { get; set; }
....
public int SomeB_Id { get; set; }
public virtual SomeModel_B SomeModel_B { get; set; }
}
I found a solution for this problem.
1) setting the IsAsync-Property in the ItemsSource-Binding.
"{Binding OrderItemViews.SOmeModel_A.SomeModel_B.SOmeField, IsAsync=true}"
The interface does not freeze, but the value appears after a while time. This will confuse some users.
2) using Include for loading include data.
For instance:
Context.SomeModel.Include(a => a.SomeModel2).Load();
but in my case Context doesn’t have Include. Why?
Which the best way to solve this problem?
Could you please give me a guidance on how should I do that or any useful resource I can read and learn about it?
Thanks
Include is not part of the standard libraries, you have to add
using System.Data.Entity;. Failing that, what is the type returned byContext.SomeModel?