简体   繁体   English

删除 Dynamics 中的实体引用 API

[英]Removing an entity reference in Dynamics API

I'm new to Microsoft Dynamics web API and I need to remove/null an entity reference (a field holding a GUID which is an ID of a record in another entity) in a batch update call.我是 Microsoft Dynamics web API 的新手,我需要在批量更新调用中删除/清空一个实体引用(一个包含 GUID 的字段,它是另一个实体中记录的 ID)。 This batch update call could contain any number of records and each record could contain any number of entity reference fields that need to be nulled.此批更新调用可以包含任意数量的记录,并且每条记录可以包含任意数量的需要清空的实体引用字段。 To set an entity reference, I'm able to do the following:要设置实体引用,我可以执行以下操作:

"gnh_address1_countryid@odata.bind":"/gnh_countries(c58790c2-ed83-e511-80f7-1458d043a570)"

However, to remove this, setting the value to null (or an empty GUID string of 0s) does not seem to work.但是,要删除它,将值设置为 null(或 0 的空 GUID 字符串)似乎不起作用。 I've come across this page我遇到过这个页面

https://msdn.microsoft.com/en-us/library/mt607875.aspx#bkmk_Removeareferencetoanentity https://msdn.microsoft.com/en-us/library/mt607875.aspx#bkmk_Removearereferencetoanentity

which tells me that I need to do a delete call for a given field that I want to remove.这告诉我需要对要删除的给定字段执行删除调用。 Is this really the only way of doing it?这真的是唯一的方法吗? That seems to me to be a lot of calls to what should be a fairly simple thing to do.在我看来,这应该是一件相当简单的事情。 From what I understand, if I had 3 records that I wanted to update, each of which had 3 entity reference fields that I wanted to remove/delete/nullify, that would be 1 call for the batch update, and then 9 subsequent delete calls.据我了解,如果我有 3 条要更新的记录,每条记录都有 3 个我想要删除/删除/取消的实体引用字段,那将是 1 次批量更新调用,然后是 9 次后续删除调用. If I had 1000 records to update, this would be an update and then 3000 delete calls.如果我有 1000 条记录要更新,这将是一个更新,然后是 3000 个删除调用。 Again, is this really the only way of doing it?再一次,这真的是唯一的方法吗? Is there no way to remove them as part of the batch update?有没有办法将它们作为批量更新的一部分删除?

Unfortunately, this is the only available way , even today. 不幸的是,这是唯一可用的方式 ,即使在今天。

Microsoft released v9 web api version, after multiple v8.x versions, but still deleting the reference property/single valued navigation property is the possible way. 微软在多个v8.x版本之后发布了v9 web api版本,但仍然删除引用属性/单值导航属性是可行的方法。 Setting null to Lookup field (Foreign Key) while update is impossible. 在更新时无法将null设置为Lookup字段(外键)。

使用Web API操作将set-null与其他字段更新组合在一起

Assign the value Guid.分配值 Guid。 empty, and create a plugin, listening on validate update, and then set the value to null in the plugin worked for me.空,并创建一个插件,监听验证更新,然后在为我工作的插件中将值设置为 null。 it is a more simple approach than building an action.这是一种比构建动作更简单的方法。 I needed this approach because i am updating several fields in same patch from web-api code.我需要这种方法,因为我正在从 web-api 代码更新同一个补丁中的几个字段。

If you are using Kipon.Solid.Plugin framework for buidling plugins, the plugin method will be as simple as below:如果您使用 Kipon.Solid.Plugin 框架来构建插件,插件方法将如下所示简单:

public void OnValidateUpdate(Entities.kp_responsibilitymatrix target)
{
      if (target.kp_Solution != null && target.kp_Solution.Id == Guid.Empty)
      {
          target.kp_Solution = null;
      }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Dynamics CRM WEB API-从实体参考中选择字段 - Dynamics CRM WEB API- Select field from entity reference 在Dynamics 365 API中,当所有者可以是系统用户或团队时,如何详细参考适当的所有权实体? - In Dynamics 365 API, How to reference proper ownership entity for detail when owner can be systemuser or team? 如何在不引用特定实体的情况下调用 Dynamics web api 绑定自定义操作? - How to call Dynamics web api bound custom action without a reference of a specific entity? 通过调用Dynamics 365 API获取实体类型 - Get Entity Types by calling Dynamics 365 API Dynamics API返回实体字段和字段元数据 - Dynamics API returning entity fields and field metadata 从Dynamics CRM 2013的导航栏中删除实体 - Removing an Entity from Dynamics CRM 2013's Navigation Bar 如何通过API在CRM Dynamics中创建自定义实体本身 - How to create custom entity itself in CRM Dynamics via API 使用备用键查找 Dynamics 365 实体,该键是 API 的查找属性 - Lookup Dynamics 365 entity with alternate key that is a lookup property with the API 是否可以通过API在Dynamics CRM中定义具有属性的新实体类型? - Is it possible to define a new entity type with attributes in Dynamics CRM through API? 使用实体元数据早期绑定调用 Dynamics Web API - Calling Dynamics Web API with Entity metadata early binding
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM