locked
Basic LINQ syntax + Astoria RRS feed

  • Question

  • Hello,

    This question is a subset of my previous question. I'm trying to use LINQ in my Silverlight project. I follow this example from Quick Start.

    The example mentioned like that for update operation. ~

    using System;
    using Microsoft.Data.WebClient;
    using System.Linq;
    using NorthwindModel;

    namespace TestApplication
    {
    class Program
    {
    static void Main(string[] args)
    {
    NorthwindEntities ctx = new
    NorthwindEntities("http://localhost:1234/Northwind.svc");
    ctx.MergeOption = MergeOption.AppendOnly;

    var c1 = (from c in ctx.Categories
    where c.CategoryName == "NewCategory1"
    select c).First();

    c1.CategoryName = "UpdatedCategory";

    ctx.UpdateObject(c1);
    ctx.SaveChanges();
    }
    }
    }

    In ADO.NET Data Service Silverlight Addon, there is no ctx.TableName. (Any idea?)

    So, I wrote like that.

    WebDataContext ctx = new WebDataContext("http://localhost:50527/WebDataService1.svc");
    ctx.MergeOption = MergeOption.AppendOnly ;

    WebDataQuery<Customer> customers = ctx.CreateQuery<Customer>("/Customers?$orderby=CustomerID");

    var customer = (from c in customers
    where c.CustomerID == 1007
    select c).First();

    customer.CustomerName = "Jack";


    //ctx.AttachObject("Customers", editCustomer);
    ctx.UpdateObject(customer);
    ctx.SaveChanges();

    I got the error "Data at the root level is invalid. Line 1, position 1." at LINQ line.

    Any idea about this? Thanks in advance.
    Sunday, January 27, 2008 4:44 AM

Answers

  • It is unsupported to provide more then the Entity set name in the call to CreateQuery - for example adding the Order By query option into the URI is not supported.  In this case an invalid URI is being generated and sent to the server.

     

     

    Sunday, March 9, 2008 2:56 AM
    Moderator

All replies

  • try removing the .First() and just access customer[1].  If that does the trick, this is likely a bug we need to address.  Also, please see my reply about update not being properly supported by the current CTP drop of the Silverlight client library for ADO.NET Data Services which targets the SL 1.1 September Alpha Refresh

     

    Thanks for the feedback...

     

    -Mike

     

    Tuesday, January 29, 2008 4:43 AM
  • Thanks for your reply, Mike

    I tried like that. It doesn't throw the exception but I dont get the customer object. I can't access like customer.CustomerID in watch windows at runtime. Actually, I wanted to query all customers firstly. And then, I want to select one customer by using LINQ.

    WebDataQuery<Customer> customers = ctx.CreateQuery<Customer>("/Customers(1001)");

    var customer = (from c in customers
                                                    select c);

    Thanks again.
    Tuesday, January 29, 2008 11:33 AM
  • It is unsupported to provide more then the Entity set name in the call to CreateQuery - for example adding the Order By query option into the URI is not supported.  In this case an invalid URI is being generated and sent to the server.

     

     

    Sunday, March 9, 2008 2:56 AM
    Moderator