Solved

Silverlight odata question

Posted on 2010-11-30
2
907 Views
Last Modified: 2012-05-10
Hello,
I am learing about odata and Silverlight.  I have a service reference to the Northwind odata and a DataServiceCollection.  When I try to do LoadAsync it fails with an error:
System.InvalidOperationException: This operation is only supported on collections that are being tracked.

Here is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightTestOdata
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }


        private ServiceReference1.NorthwindEntities svc;

        private System.Data.Services.Client.DataServiceCollection<ServiceReference1.Product> productBindingCollection;

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            svc = new ServiceReference1.NorthwindEntities(new Uri(@"http://services.odata.org/Northwind/Northwind.svc"));
            
            productBindingCollection = new System.Data.Services.Client.DataServiceCollection<ServiceReference1.Product>();

            productBindingCollection.LoadCompleted += new EventHandler<System.Data.Services.Client.LoadCompletedEventArgs>(productBindingCollection_LoadCompleted);

            productBindingCollection.LoadAsync();
            
        }

        void productBindingCollection_LoadCompleted(object sender, System.Data.Services.Client.LoadCompletedEventArgs e)
        {
           if (e.Error == null)
           {
              dataGrid1.DataContext = productBindingCollection;
           }
           else
           {
              MessageBox.Show(e.Error.Message);
           }
        }
    }
}

Open in new window

0
Comment
Question by:Qu311
  • 2
2 Comments
 

Author Comment

by:Qu311
ID: 34251070
I added a DataServiceQuery which got rid of the error but I don't see any data displayed in my Datagrid.
private void button1_Click(object sender, RoutedEventArgs e)

        {

            svc = new ServiceReference1.NorthwindEntities(new Uri(@"http://services.odata.org/Northwind/Northwind.svc"));

            

            productBindingCollection = new System.Data.Services.Client.DataServiceCollection<ServiceReference1.Product>();



            productBindingCollection.LoadCompleted += new EventHandler<System.Data.Services.Client.LoadCompletedEventArgs>(productBindingCollection_LoadCompleted);



            DataServiceQuery<ServiceReference1.Product> query = svc.Products;



            productBindingCollection.LoadAsync(query);

            

        }

Open in new window

0
 

Accepted Solution

by:
Qu311 earned 0 total points
ID: 34251490
I changed DataContext to ItemsSource and it worked.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This tutorial will show you how to add an attribute to an XML (http://en.wikipedia.org/wiki/XML) stream returned from a Windows Communication Foundation (http://en.wikipedia.org/wiki/Windows_Communication_Foundation) (WCF) Web Service.  Some knowled…
Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now