zoukankan      html  css  js  c++  java
  • OData V4 系列 .net应用

          OData 学习目录

         添加 OData Client Code Generator 扩展

         

          

      添加OData T4生成工具

         

            修改 T4 模板的 MetadataDocumentUri

           

            运行Web项目,之后重新保存 T4模板,保存成功后会生成代理类  (必须保证项目运行或把项目发布到IIS,保证URL可以正常访问

           

             操作代码如下:        

    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();
    
            }
  • 相关阅读:
    ant
    maven 构建web项目
    什么叫openapi
    dubbo学习
    Java 获取环境变量
    配置文件书写对象的几种方式
    怎么改svn的登陆账号
    Android 它们的定义View (一)
    eclipse建立cocos2d-x开发环境
    Android——采用SQLiteDatabase操作SQLite数据库
  • 原文地址:https://www.cnblogs.com/Fengger/p/4959105.html
Copyright © 2011-2022 走看看