locked
data service insert RRS feed

  • Question

  • Hi!
    I allready ask the question but maybe the question wasn't right. I'm creating some website with ajax updating the data into database. After I make insert with this line of javascript code

    ds.insert({diskusijskaGrupa: { __metadata: { uri: 'diskusijskaGrupa(' + idDiskGrupe + ')'} }, osoba: { __metadata: { uri: "osoba/?$filter=JMBAG eq '" + studJMBAG + "'"}} }, "studentDiskusijskaGrupa", ADPopuniStudente, ADpGreska);
    i get this error:

    {
    "error": {
    "code": "", "message": {
    "lang": "hr-HR", "value": "An error occurred while processing this request."
    }, "innererror": {
    "message": "A single resource was expected for the result, but multiple resources were found.", "type": "System.InvalidOperationException", "stacktrace": "   at System.Data.Services.Providers.ObjectContextServiceProvider.GetResource(IQueryable query, String fullTypeName)\r\n   at System.Data.Services.Serializers.Deserializer.GetResource(SegmentInfo segmentInfo, String fullTypeName, IDataService service, Boolean checkForNull)\r\n   at System.Data.Services.DataService`1.System.Data.Services.IDataService.GetResource(RequestDescription description, Int32 segmentIndex, String typeFullName)\r\n   at System.Data.Services.Serializers.Deserializer.CreateObjectFromUri(ResourceType resourceType, SegmentInfo segmentInfo, RequestDescription description, Boolean verifyETag, Boolean checkForNull, Boolean replaceResource)\r\n   at System.Data.Services.Serializers.Deserializer.CreateObjectFromUri(ResourceType resourceType, SegmentInfo segmentInfo, String uri, Boolean verifyETag, Boolean checkForNull)\r\n   at System.Data.Services.Serializers.JsonDeserializer.CreateObject(Object jsonObject, SegmentInfo segmentInfo, Boolean topLevel, Boolean& existingRelationship)\r\n   at System.Data.Services.Serializers.JsonDeserializer.PopulateProperties(Hashtable jsonObject, Object resource, ResourceType parentResourceType)\r\n   at System.Data.Services.Serializers.JsonDeserializer.CreateObject(Object jsonObject, SegmentInfo segmentInfo, Boolean topLevel, Boolean& existingRelationship)\r\n   at System.Data.Services.Serializers.JsonDeserializer.CreateSingleObject(SegmentInfo segmentInfo)\r\n   at System.Data.Services.Serializers.Deserializer.ReadEntity(RequestDescription requestDescription)\r\n   at System.Data.Services.Serializers.Deserializer.HandlePostRequest(RequestDescription requestDescription)\r\n   at System.Data.Services.DataService`1.HandlePostOperation(RequestDescription description, IDataService dataService)\r\n   at System.Data.Services.DataService`1.ProcessIncomingRequest(RequestDescription description, IDataService dataService)\r\n   at System.Data.Services.DataService`1.HandleNonBatchRequest(RequestDescription description)\r\n   at System.Data.Services.DataService`1.HandleRequest()"
    }
    }
    }


    the problem is that table diskusijskaGrupa have only one entry with that id and olso osoba have only one entry with that JMBAG. Could someone please help me.
    Thursday, April 16, 2009 10:47 AM

Answers

  • Hi,

    First, I assume that diskusijskaGrupa\osoba is a navigation property to a collection of 'osoba' entities, based on what you're trying to do.

    The URI you are using for this navigation property, osoba/?$filter=..., is not valid for a navigation property during insert. A URI to a specific entity(for a reference property) or an array of specific URIs (for a collection like yours) are the allowed forms.

    You will either need to perform the filtered query first and then generate the array of URIs, or perform the insert swithout any linked 'osoba' entities and then add the links with subsequent requests.

    The error you are seeing is presumably because the URI is expected to result in a single entity, and its yielding a collection. I don't know if there being only one item in the collection would make a difference here.

    Matt Meehan, ADO.NET Data Services (Astoria)
    Thursday, April 16, 2009 3:56 PM
    Moderator

All replies

  • Hi,

    First, I assume that diskusijskaGrupa\osoba is a navigation property to a collection of 'osoba' entities, based on what you're trying to do.

    The URI you are using for this navigation property, osoba/?$filter=..., is not valid for a navigation property during insert. A URI to a specific entity(for a reference property) or an array of specific URIs (for a collection like yours) are the allowed forms.

    You will either need to perform the filtered query first and then generate the array of URIs, or perform the insert swithout any linked 'osoba' entities and then add the links with subsequent requests.

    The error you are seeing is presumably because the URI is expected to result in a single entity, and its yielding a collection. I don't know if there being only one item in the collection would make a difference here.

    Matt Meehan, ADO.NET Data Services (Astoria)
    Thursday, April 16, 2009 3:56 PM
    Moderator
  • Thanks for your answer. The problem was that I was using.../$filter=JMBAG. And the JMBAG is primary key and when I puted osoba(JMBAG) everithing worked fine.

    Thank u a lot!!!
    Thursday, April 16, 2009 9:34 PM