OData 學習目錄html
添加 OData Client Code Generator 擴展工具
添加OData T4生成工具學習
修改 T4 模板的 MetadataDocumentUrispa
運行Web項目,以後從新保存 T4模板,保存成功後會生成代理類 (必須保證項目運行或把項目發佈到IIS,保證URL能夠正常訪問)代理
操做代碼以下: code
static void Main(string[] args) { const string serviceUri = "http://localhost:1088/OData"; var container = new Container(new Uri(serviceUri)); GetProducts(container); var pro = new Product {Name = "Client OData", Price = 1024, Category = "IT"}; container.AddToProducts(pro); pro = new Product { Name = "Client OData", Price = 1024, Category = "IT" }; container.AddToProducts(pro); var list = container.Products.Where(c=>c.Id==1).ToList(); var proUpdate = list.FirstOrDefault(); if (proUpdate != null) { proUpdate.Name = "Update Client OData"; } container.UpdateObject(proUpdate); container.AddAndUpdateResponsePreference = DataServiceResponsePreference.IncludeContent; // Add the data to the server var response = container.SaveChanges(SaveChangesOptions.ReplaceOnUpdate); foreach (var operationResponse in response) { Console.WriteLine("Response: {0}", operationResponse.StatusCode); } Console.ReadLine(); }