2
Vote

Creating two linked subitems from single query does not work

description

I'm trying to create (using one POST request) an item with several linked sub-items.

The request is like

<entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
<category term="ItemFilter" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ItemFilterCriteria">
    <m:inline>
        <feed>
            <entry>
                <content type="application/xml">
                    <m:properties>
                        <d:Id m:type="Edm.Int32">0</d:Id>
                        <d:FieldId>1</d:FieldId>
                        <d:Value>True</d:Value>
                        <d:From m:null="true" />
                        <d:To m:null="true" />
                     </m:properties>
                </content>
            </entry>
            <entry>
                <content type="application/xml">
                    <m:properties>
                        <d:Id m:type="Edm.Int32">0</d:Id>
                        <d:FieldId>2</d:FieldId>
                    <d:Value>6</d:Value>
                    <d:From m:null="true" />
                    <d:To m:null="true" />
                 </m:properties>
            </content>
        </entry>
    </feed>
    </m:inline>
</link>
</entry>


The problem is that when the request is processed by ODataContext.cs, SetValue method crashes in
        // Search for the CreateResource or ModifyResource operation related to our target entity.
        var operation = _oDataOperations.SingleOrDefault(op => op.Entity.Equals(targetResource) && (op.Operation.Equals("CreateResource") || op.Operation.Equals("ModifyResource")));
because there are TWO CreateResource operations in array at that time.

Can anyone suggest a fix/workaround (without suggesting to use only one subitemper query :)?

comments

Airslash wrote Jun 5, 2012 at 12:21 PM

Create the items in a seperate call first and then link them afterwards.

vkplex wrote Jun 5, 2012 at 2:44 PM

thanks, it's should work, but can it be done in one call (maybe some other syntax etc)?