CRM do not support direct update of Entity Reference properties, Use Navigation properties instead

北城以北 提交于 2019-12-21 10:47:03

问题


I am using Ms Dynamic Web Api with Simple OData. I need to add new record for link entities.

I am using the below code snip and refer the documentation on https://github.com/object/Simple.OData.Client/wiki/Adding-entries-with-links

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

        var newContactLink = await  _oDataClient.For<New_project_contactses>()
                .Set(new
                {
                    _new_contact_project_name_new_value = contactData.ContatDetailsLink._new_contact_project_name_new_value,
                    new_project_contactsid = new Guid("0eb46b24-21a2-e611-80eb-c4346bc5b2d4"),
                    new_contact_type = contactData.ContatDetailsLink.new_contact_type,

                })
                .InsertEntryAsync(resultRequired: true);

i am getting exception

CRM do not support direct update of Entity Reference properties, Use Navigation properties insteadS


回答1:


Well, it is possible, but you need to use the special "@odata.bind" syntax to update your single-navigation properties.

For example, to update an account so that it references an existing primarycontactid, you can use a PATCH operation to the /api/data/v8.2/accounts endpoint with the following body:

{
   "name":"Sample Account",
   "primarycontactid@odata.bind":"/contacts(00000000-0000-0000-0000-000000000001)"
}

See https://msdn.microsoft.com/en-us/library/gg328090.aspx#Anchor_3 (it is discussed in terms of creating an entity, but it works for updating as well).




回答2:


I figure out the issue With Dynamc CRM you cannot directly update reference entities Field. You can identify reference entity properties start with "_".



来源:https://stackoverflow.com/questions/40413563/crm-do-not-support-direct-update-of-entity-reference-properties-use-navigation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!