Dynamics crm 2011 在实体中设置查找属性

Dynamics crm 2011 在实体中设置查找属性,dynamics-crm-2011,Dynamics Crm 2011,我有一个实体叫做Samples。我有很多字段,其中一个是ProjectLocation下拉列表 现在,我使用这段代码通过WCF在CRM中插入Sample类型的新实例 Entity sample = new Entity("new_sample"); sample.Attributes["name"]= "Ahmed"; 这是可行的,但当我想进入项目地点时,我不知道该如何完成 这不管用 Entity projectLoc = service.Retrieve("projectlocation",

我有一个实体叫做Samples。我有很多字段,其中一个是ProjectLocation下拉列表

现在,我使用这段代码通过WCF在CRM中插入Sample类型的新实例

Entity sample = new Entity("new_sample");
sample.Attributes["name"]= "Ahmed";
这是可行的,但当我想进入项目地点时,我不知道该如何完成

这不管用

Entity projectLoc = service.Retrieve("projectlocation", (new guid here), columnset)
sample.Attributes["new_projectlocation1"] = projectLoc

可以做什么?

查找是
EntityReference
而不是
Entity
的实例。我一直认为查找是指向实体的指针(通过GUID),而不是实体本身。但是,我的文凭工作是C++的,所以我应该对指针进行大脑清洗。p> 您需要设置一个
EntityReference

sample.Attributes["new_projectlocation1"] 
  = new EntityReference("projectlocation", new guid here);

您需要更改代码以返回,以下是更新的代码:

Entity projectLoc=service.Retrieve("projectlocation",(new guid here),columnset) //retrieves a correct projectloc. 
sample.Attributes["new_projectlocation1"]=projectLoc.ToEntityReference(); //Now it'll work