2013-01-01 65 views
1

我有一个名为的实体样本。里面说我有很多字段,其中一个是ProjectLocation下拉列表。在实体中设置查找属性

现在我使用此代码通过WCF在CRM中插入样本的新实例。

Entity sample = new Entity("new_sample"); 
sample.Attributes["name"]= "Ahmed"; 

这个工作,但是当我要进入ProjectLocation我没有任何想法,应该如何来实现。

这不起作用。

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

可以做些什么?

回答

1

你需要改变你的代码返回一个EntityReference,这里是更新后的代码:

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

查找是EntityReference的实例,而不是Entity。我总是将一个查找想象成一个指针(通过一个GUID)给一个实体,而不是实体本身。但是再一次,我的文凭工作是用C++编写的,所以我应该对指针进行大脑清洗。 :)

0

您需要设置一个EntityReference

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