Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Silverlight odata question

Posted on 2010-11-30
2
911 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In previous Articles, we have discussed how we can upload a file using .asmx web service and isolated storage space. Here, in continuation to the topic, I am going to discuss how we can use WCF for the same purpose. Steps: 1.Create the silverli…
While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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