Solved

Silverlight odata question

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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

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…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

696 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