locked
Add multiple associations to many-end Navigation Property RRS feed

  • Question

  • Hi, guys,

    I have these two entity classes (roughly enough to get the point):

    public class Company
    {
     public EntitySet<Person> People {...}
    }
    
    public class Person
    {
     private EntityRef<Company> company;
     public Company Company
     {
      get { return company.Entity; }
      set { company.Entity = value; }
     }
    }
    
    My DataContext exposes the two: IQueryables Companies and People. And implements IUpdatable.

    I am able to do all the CRUD stuff. I can even add a single association to many-end NavigationProperty like so:
    HTTP: POST
    URL: Companies(1)/$links/People
    Data: {uri:"People(1)"}
    According to the thorough documentation here, it is possible to insert multiple associations. Quote: "When the association end that needs to be changed has cardinality > 1, the $links URI construct is also used; however the payload may be a single URI or a list of URIs."

    What I can't figure out is how to send this list instead of a single URI. I've tried these options with no success using the same HTTP Request Type and the same URL:
    { d: [{uri: "People(2)"}, {uri: "People(3)"}]}
    
    { d:[
     {__metadata: {uri: "People(2)"}}, 
     {__metadata: {uri: "People(3)"}}
    ]}

    That respond with the error message: "Missing URI element. For link operations, URI element must be specified."

    [{uri: "People(2)"}, {uri: "People(3)"}]

    That resolve in: "Error processing request stream. The request should be a valid top-level resource object."

    I've tried some even more pointless ones to no avail.

    Any thoughts?

     


    Bigsby, Lisboa, Portugal
    O que for, quando for, é que será o que é...
    Wenn ist das Nunstruck git und Slotermeyer? Ja! ... Beiherhund das Oder die Flipperwaldt gersput!
    http://bigsby.eu
    Saturday, July 31, 2010 7:53 PM

Answers

  • I do not think the current server implementation supports multiple associations using $links uri. But here is something you can do -

    HTTP: MERGE
    URL: Companies(1)
    Data: { People: [
     { __metadata: { uri: "People(2)" } }
     { __metadata: { uri: "People(3)" } }
          ]}

    Hope this helps. Basically, you are trying to update Companies(1) and in the payload, you are giving a bunch of uri's for the People navigation property to bind to.

    Thanks
    Pratik


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, August 2, 2010 6:46 PM
    Moderator

All replies

  • Further attempts.

    Data: {uri:"People(3,4)"}
    Result: The number of keys specified in the URI does not match number of key properties for the resource 'Service.Person'.

    Data: {uri:"People(3),People(4)"}
    Result: Bad Request - Error in query syntax.



    Bigsby, Lisboa, Portugal
    O que for, quando for, é que será o que é...
    Wenn ist das Nunstruck git und Slotermeyer? Ja! ... Beiherhund das Oder die Flipperwaldt gersput!
    http://bigsby.eu
    Sunday, August 1, 2010 3:27 PM
  • I do not think the current server implementation supports multiple associations using $links uri. But here is something you can do -

    HTTP: MERGE
    URL: Companies(1)
    Data: { People: [
     { __metadata: { uri: "People(2)" } }
     { __metadata: { uri: "People(3)" } }
          ]}

    Hope this helps. Basically, you are trying to update Companies(1) and in the payload, you are giving a bunch of uri's for the People navigation property to bind to.

    Thanks
    Pratik


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, August 2, 2010 6:46 PM
    Moderator