locked
DataServiceCollection only loading the first item in a collection RRS feed

  • Question

  • If I call the service with LINQ like this

    var details = (from T in db.TestData where T.Field1 == "something" select T)

    and then do "details.ToList()" I get x number of objects. (more than 1)
    but if I do the following

    var details = new DataServiceCollection<TestObject>(from T in db.TestData where T.Field1 == "something" select T)

    I get only "1" object.

    I tried to iterate through the list and add each item into the DataServicesCollection but I get the following error:

    "An item could not be added to the collection. When items in a DataServiceCollection are tracked by the DataServiceContext, new items cannot be added before items have been loaded into the collection."

    Tuesday, November 25, 2014 8:52 PM

All replies

  • Hello ImGonaRot,

    >> I get only "1" object.

    This sounds strangely, as far as I know, the DataServiceCollection does not have an inside filter to exclude records.

    According to your description, I made a test to try to reproduce this issue with below query:

    RestReference.WCFDBEntities db = new RestReference.WCFDBEntities(new Uri("http://localhost:57232/WcfDataService1.svc"));
    
                var result = new DataServiceCollection<Client.RestReference.Order>(from order in db.Orders where order.OrderName == "1" select order);
    
                Client.RestReference.Order newOrder = new RestReference.Order() { OrderID = 4, OrderName = "4" };
    
                result.Add(newOrder);
    
                db.SaveChanges();

    However, in my computer, it returns the excepted result(three entries are returned since in my database, there are three records whose name is “1”) and the add operation is also successfully.

    My test table is very simple:

    CREATE TABLE [dbo].[Order] (
    
        [OrderID]   INT           NOT NULL,
    
        [OrderName] NVARCHAR (50) NOT NULL,
    
        PRIMARY KEY CLUSTERED ([OrderID] ASC)
    
    );

    I use the WCF Data Service 5.6.2,Entity Framework 6.X, VS2013 and .NET Framework 4.5.

    Please have a try with my table and the similar environment to check if it still returns one item when using DataServiceCollection?

    Or please share your test table and your test environment(version of Entity Framework , WCF Data Service and database you are using,etc.) with us so that we could make an exact test to see if we could find the caused reason.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, November 26, 2014 3:17 AM
    Moderator
  • Your code works fine.
    The problem is not WCF related.

    Microsoft.OData.Client.DataServiceCollection is the class that has the problem. 
    I will post this information on the OData forum when I can find the forum...

    Thanks for your help.

    Monday, December 1, 2014 1:21 PM
  • Hello ImGonaRot,

    You could post Odata related issues to this forum:

    http://odata.codeplex.com/workitem/list/basic

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, December 2, 2014 3:07 AM
    Moderator