2013-01-01 64 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); 
相關問題