?
Solved

Silverlight odata question

Posted on 2010-11-30
2
Medium Priority
?
917 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
[X]
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
  • 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

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…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

770 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