?
Solved

Silverlight odata question

Posted on 2010-11-30
2
Medium Priority
?
918 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
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 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…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

650 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