RIA services: Load returning no data
In the BookClub example application from nikhilk Kothary, a combobox is used to display book categories开发者_运维技巧.
It is like this in the viewmodel class (the application is using the MVVM pattern):
private ReferenceDataContext _referenceData;
public BookClubModel() { // Constructor _referenceData = new ReferenceDataContext();
_referenceData.Load(_referenceData.GetcategoriesQuery(), false);
}
Then there is a property to which the comboxbox is bound:
public IEnumerable Categories { get { return _referenceData.Categories; } }
Why is this working? Shouldn't we have a "completed" event handler for the load operation?
If I want to fill a IEnumerable property in the constructor, then it is not working:
private ReferenceDataContext _referenceData;
private IEnumerable _categories;
public BookClubModel() { // Constructor _referenceData = new ReferenceDataContext();
_referenceData.Load(_referenceData.GetcategoriesQuery(), false);
_categories = _referenceData.Categories; _referenceData.Categories was what we were returning in the Categories property above.
}
Why does it work in one case and not for the other?
Daniel
In first case Categories
is reference to _referenceData.Categories
. And when _referenceData.Categories
collection was updated, Categories
also updated.
In second case you need event handler for Load
operation, then do what you want with loaded entities.
Internally when you call Load, query to database is performing and when result is fetched then called load operation callback. Load operation is async operation and you need to keep in mind that fact
精彩评论