更新使用 Microsoft.PowerPlatform.Dataverse.Client.Dynamics 的导航实体的方法。

huangapple go评论70阅读模式
英文:

how to update Navigation entity with Microsoft.PowerPlatform.Dataverse.Client.Dynamics

问题

I am using Microsoft.PowerPlatform.Dataverse.Client.Dynamics package to update CRM entity.

要更新普通字段,

entity.Attributes["ecg_proposal_url"] = sendURL ;
await client.UpdateAsync(entity);

可以正常工作。但是当我尝试对导航字段(指向用户)执行相同操作时,我收到错误消息:

"CRM 不支持直接更新实体引用属性,请使用导航属性"
搜索没有显示任何示例。而且文档非常有限。
如何使用字段名称 "_ecg_proposal_written_by_value" 进行更新?
谢谢。
引发错误的代码是:

entity.Attributes["_ecg_proposal_written_by_value"] = writtenByID;

或者

entity.Attributes["ecg_proposal_written_by"] = writtenByID;

应该使用用户 ID。

英文:

I am using Microsoft.PowerPlatform.Dataverse.Client.Dynamics package to update CRM entity.

to update a normal field,

entity.Attributes["ecg_proposal_url"] = sendURL ;
await client.UpdateAsync(entity);

works fine. but when I try the same with a navigation field (pointing to user) , I get error:

"CRM do not support direct update of Entity Reference properties, Use Navigation properties instead"
The search did not show any example. Also the DOCs are very slim.
How do I update it with field name "_ecg_proposal_written_by_value" ?
Thank you.
The code that causes the error is:

entity.Attributes["_ecg_proposal_written_by_value"] = writtenByID;

Or

entity.Attributes["ecg_proposal_written_by"] = writtenByID;

it should have a user ID

答案1

得分: 1

一个查找字段需要指定与其关联的表。
使用 C# SDK 时,您需要分配一个 EntityReference 对象。

类似于:

entity["ecg_proposal_written_by"] = new EntityReference("systemuser", writtenByID);

假设查找字段指向 systemuser(用户)表。

请注意,使用 C# SDK 时,您需要使用字段的逻辑名称(ecg_proposal_written_by),而不是在 Web API / OData 4.0 语法中使用的名称(在您的情况下是 _ecg_proposal_written_by_value)。

英文:

a lookup field needs to specify the table associated with it.
With the C# SDK you need to assign a EntityReference object.

Something like:

entity["ecg_proposal_written_by"] = new EntityReference("systemuser", writtenByID);

assuming the lookup points to the systemuser (User) table.

Note that with the C# SDK you need to use the logical name of the field (ecg_proposal_written_by) and not the name used with Web API / OData 4.0 syntax (in your case _ecg_proposal_written_by_value)

huangapple
  • 本文由 发表于 2023年4月13日 15:59:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76003013.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定