以前有篇博文介紹瞭如何獲取查找字段的name值(跳轉),本篇在此基礎上再延伸下,實現的效果相似於EntityReference,能夠取到查找字段的id,name,localname。json
這裏我以客戶實體爲例,定義了一個叫new_city的查找字段,如今獲取它的值api
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://xx/api/data/v8.0/accounts(1D539D5B-D8B2-E611-80EB-C255C0417B60) ?$select=_new_cityid_value"); req.Credentials = new NetworkCredential(name, pwd, domain); req.Method = "Get"; req.Accept = "application/json"; req.ContentType = "application/json; charset=utf-8"; req.Headers.Set("OData-MaxVersion", "4.0"); req.Headers.Set("OData-Version", "4.0"); req.Headers.Set("Prefer", "odata.include-annotations=*"); using (HttpWebResponse res = (HttpWebResponse)req.GetResponse()) { StreamReader read = new StreamReader(res.GetResponseStream()); string result = read.ReadToEnd(); }從上面的代碼能夠看到,和以前的博文中的惟一區別在於head中的prefer,咱們把OData.Community.Display.V1.FormattedValue替換成了*。
咱們來看看返回的json值,查找字段相關的信息都出來了。app
{ "@odata.context":"http://xx/api/data/v8.0/$metadata#accounts(_new_cityid_value)/$entity","@odata.etag":"W/\"1421510\"", "_new_cityid_value@Microsoft.Dynamics.CRM.associatednavigationproperty":"new_cityid", "_new_cityid_value@Microsoft.Dynamics.CRM.lookuplogicalname":"new_city", "_new_cityid_value@OData.Community.Display.V1.FormattedValue":"\u4e0a\u6d77", "_new_cityid_value":"41017df2-2b7b-e611-9424-952f64877d17", "accountid":"1d539d5b-d8b2-e611-80eb-c255c0417b60" }