Preferred way to load from different sources

Nov 30, 2011 at 10:38 PM

Hello,

If this already have been answered I apologize in advance.

I have a scenario where I query a search service and use AgFx to store the result. The order of the items is rather important. The search service only gives me some information, so I then have to query another service to find all of the required information.

What would be the preferred way to do this?

I have tried and failed the following way in 'Deserialize' of the Load Model for the searches.

foreach(SearchItem item in request.SearchResults)
{
vm.SearchResults.Add(
DataManager.Current.Load<DetailedItem>(item.id).DetailedItem);
}

vm.SearchResults = ObservableCollection<DetailedItem>;

The result from the DetailedItem is returned after a while, but the SearchResults does not reflect the update. I'm probably missing something rather obvious. Help? :)
 

 

 

Coordinator
Dec 2, 2011 at 3:54 PM

Hi IamB -

You don't want to do a Load from your Deserialize from a variety of reasons.

The question I have about the above is about how much of the data comes back in the search results?  Is it just the ID of the detailed item, or more data about it.

If it's just the ID, you probably want to just create a wrapper to make it easy:

foreach(SearchItem item in request.SearchResults) 
{
vm.SearchResults.Add(new DetailedItemWrapper(item.id)
); 
}

Then in DetailedItemWrapper:

public class DetailedItemWrapper  {

       private string _id;

	public DetailedItem Value {
		get {

			return DataManager.Current.Load<DetailedItem>(_id);

		} 

	}

}

You could do some work to merge the two, or pre-populate with the data from the Search Results, but that's the general idea.  You want the "get" from databinding to kick off the next Load so that eveything happens on Demand and you don't do Loads the UI will never show.

So your ItemTemplate would be something like:

<StackPanel DataContext="{Binding}">

	<TextBlock Text="{Binding Value.Title}"/>

        <TextBlock Text="{Binding Value.Description}"/>

</StackPanel>

Shawn

Dec 2, 2011 at 7:35 PM

Thanks for the reply Shawn, I'll try this approach instead. The search result also gives back a search rank thats rather important, but I'll try this and see how I can go from there. Thanks again :)