OData client only returning last entry in sequence?
I'm hoping that I'm just using the API incorrectly, but for some reason, when I query my oData service from wp7, I am only receiving the last entry in the sequence. I'm pretty sure the service is working just fine as I'm able to just visit the oData query URL in the browser and get the correct results. However, the following method only ends up displaying one item on the list.
I based the following code from the sample at this blog post: http://chriskoenig.net/2010/10/30/odata-v2-and-windows-phone-7/
The observable collection which is passed in is the one which is bound to the wpf listbox.
private static void LoadRuntimeData(ObservableCollection<CategoryItem> items)
{
var catalog = GetCatalog();
var queryUri = new Uri("/Categories?&$orderby=Name", UriKind.Relative);
var categories = new DataServiceCollection<Category>(catalog);
var queryHandle = App.ViewModel.StartQuerying();
categories.LoadAsync(queryUri);
categories.LoadCompleted += (e, c) =>
{
using (queryHandle)
{
var serverItems = categories.Select(k => new CategoryItem
{
Name = k.Name,
Description = k.Description
});
开发者_运维问答 items.Clear();
foreach (var item in serverItems)
{
items.Add(item);
}
}
};
}
Any tips would be greatly appreciated.
Edit: per a comment below, I've uploaded the source code in which this issue is reproducible: http://khanviewer.codeplex.com/
Taking a quick stab at this (and I suspect that Chris would know better).
But don't you need to somehow identify/tag with an attribute a primary key column (the property or properties that define uniqueness).
I know I have run into something similar to this with RIA Services, and the issue there was that I wasn't setting a value for the unique identifier column. As a result I saw all my data come down, but the when the client got the data it saw all the data as a single record.
Jay
精彩评论