Search code examples
dynamics-crmsimple.odatasimple.odata.clientdynamics-crm-webapi

Simple Odata With Ms Dynamic 2016 Web API insert return null


I am using simple Simple.Odata API to insert new entity data into Ms Dynamic CRM Web api and use the following code snip

        var newContactData = await _oDataClient
            .For<Contacts>()
               .Set(new
               {
                   firstname = contactData.ContatDetails.firstname,
                   lastname = contactData.ContatDetails.lastname,
                   emailaddress1 = contactData.ContatDetails.emailaddress1
               })
               .InsertEntryAsync(true);

This code snip created new entity data but the Problem is newcontactData is always null. According to documentation newcontactData object should have newly created object data. see the link for documenation https://github.com/object/Simple.OData.Client/wiki/Adding-entries


Solution

  • By default when creating a record no data is returned, the new record id is returned in the header (OData-EntityId). This differs from the older 2011 endpoint where the record is returned by default.

    https://msdn.microsoft.com/en-us/library/gg328090.aspx#bkmk_basicCreate

    In the latest version of CRM 8.2/Dynamics 365 you have the option to return all the attributes by passing the Prefer: return=representation header.

    https://msdn.microsoft.com/en-us/library/gg328090.aspx#bkmk_createWithDataReturned