之前的博文中有介绍过,Web Api中的一个删除单个属性的Api但没提供查找字段的删除方法,本篇补充上,这里给出的示例代码是C#的(主要看url的拼接),看下url中最后的/$ref,这个标示表明了当前删除的字段是一个查找类型的,区别就在这。
string weburi = System.Configuration.ConfigurationManager.AppSettings["WebUri"]
+ entityName +"(" + guid.Replace("{", "").Replace("}", "") + ")/" + propertyName + "/$ref";
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(weburi);
req.Credentials = new NetworkCredential(username, pwd, domain);
req.Method = "DELETE"; req.ContentType = "application/json; charset=utf-8";
req.Headers.Add("OData-MaxVersion", "4.0");
req.Headers.Add("OData-Version", "4.0");
using (HttpWebResponse res = (HttpWebResponse)req.GetResponse())
{ }