关联实体时,其名称属性未使用引用实体正确初始化

时间:2013-01-07 17:23:07

标签: dynamics-crm-2011 dynamics-crm

我在自我引用的1:N关系中遇到了这个问题 我试图将实体A(类型new_transaction)与实体B(相同类型)相关联 该关联工作正常(我在DB- 'new_relatedTransactionId'列中检查了正确更新) 但是,名称列('new_relatedTransactionIdName')设置为NULL,导致表单显示一个空文本框...
enter image description here

我尝试过以下方法,但没有成功 1。

var rel = new Relationship(relationshipName) {PrimaryEntityRole = EntityRole.Referenced};
EntityReferenceCollection relatedEntities = new EntityReferenceCollection();
relatedEntities.Add(relatedTransaction.ToEntityReference());
crmServiceContext.Associate(new_transaction.EntityLogicalName,sourceTransaction.Id,rel,relatedEntities);

2

sourceTransaction.lv_relatedtransactionid = relatedTransaction.ToEntityReference();
crmServiceContext.UpdateObject(sourceTransaction);

3

crmServiceContext.AddLink(sourceTransaction, new Relationship(relationshipName) { PrimaryEntityRole = EntityRole.Referenced }, relatedTransaction);

我尝试转换EntityRole.ReferencedEntityRole.Referencing,但仍然没有运气 有人遇到过类似的问题吗?

1 个答案:

答案 0 :(得分:1)

选项2是我创建此关系的首选方法。

字段'new_relatedTransactionIdName'未存储在数据库中,您实际上是在查看SQL视图。

如果此字段为null,则表示由new_relatedTransactionId中的Guid引用的实体记录的主要字段为空。

每个实体都有一个文本字段定义为其主要字段。此字段的值(不一定是必填字段,因此最终可能为空白)将显示在图像的文本框中。

您没有定义特定于该关系的此值,它是在创建和/或更新实体记录时创建的,并且在关系中涉及该实体的任何位置使用。