2017-08-06 47 views
-2

我想了解实体引用的使用(在crm 2011中)我在网上找到许多实体引用的例子,主要是查找字段,但我需要一个absoulte descreption。实体引用仅用于查找字段的使用情况吗?我可以使用简单的实体来获取我的数据吗?实体可以替换实体引用吗? 我的问题不仅是关于entityreference和entity之间的区别,还关于entityreference的定义以及为什么/在哪里使用它。 有人可以请这个问题清楚。什么是实体参考定义

+0

[Convert EntityReference to Entity](https://stackoverflow.com/questions/15277597/convert-entityreference-to-entity) –

+0

@ArunVinoth在发布我的问题之前,我看到了答案,它不是清楚,我不认为我的问题是重复的。 – Damkulul

回答

7

动态CRM开发记录被称为实体,由属性组成。当属性是查找(即对另一个实体的引用)时,它属于EntityReference类型。 EntityReference类型是必需的,因为它必须传达实体的逻辑名称和特定记录的id(一个Guid)。

IOrganizationService service = GetService(); //TODO: Implement GetService() 

//From: https://msdn.microsoft.com/en-us/library/gg328149.aspx 

Entity contact = new Entity("contact"); 
contact.Attributes["firstname"] = "ContactFirstName"; 
contact.Attributes["lastname"] = "ContactLastName"; 
Guid contactId = service.Create(contact); 

Entity account = new Entity("account"); 
account["name"] = "Test Account1"; 
EntityReference primaryContactId = new EntityReference("contact", contactId); 
account["primarycontactid"] = primaryContactId; 

一个Entity对象不能被用作EntityReference因为类型不同。 Entity有一个方法返回EntityReference,Entity.ToEntityReference()

重要

有关EntityReference关键的东西是,它同时包含逻辑名称和记录的ID

Dynamics CRM中有几个区域,例如使用Customer数据类型时,Lookup可能引用多个实体类型。在这些情况下,Dynamics CRM无法仅依靠Guid作为记录标识符。