CRM不支持实体参考属性的直接更新,而是使用导航属性 [英] CRM do not support direct update of Entity Reference properties, Use Navigation properties instead

查看:91
本文介绍了CRM不支持实体参考属性的直接更新,而是使用导航属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有简单OData的Dynamic Web As女士.我需要为链接实体添加新记录.

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

我正在使用下面的代码片段,请参阅以下文档: https://github.com/object/Simple.OData .Client/wiki/使用链接添加条目

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);

我正在例外

CRM不支持直接更新实体引用属性,请使用 代替导航属性S

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

推荐答案

可以,但是您需要使用特殊的"@ odata.bind"语法来更新单导航属性.

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

例如,要更新帐户以使其引用现有的primarycontactid,可以对具有以下内容的/api/data/v8.2/accounts端点使用PATCH操作:

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)"
}

请参见 https://msdn.microsoft.com/zh-CN/library/gg328090.aspx#Anchor_3 (已在创建实体时进行了讨论,但它也可用于更新).

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).

这篇关于CRM不支持实体参考属性的直接更新,而是使用导航属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆