OData V4 系列 .net应用

时间:2022-04-27 09:57:49

OData 学习目录

添加 OData Client Code Generator 扩展

OData V4 系列 .net应用

OData V4 系列 .net应用

  添加OData T4生成工具

OData V4 系列 .net应用

修改 T4 模板的 MetadataDocumentUri

OData V4 系列 .net应用

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

OData V4 系列 .net应用

操作代码如下:

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 = , Category = "IT"};
container.AddToProducts(pro); pro = new Product { Name = "Client OData", Price = , Category = "IT" };
container.AddToProducts(pro); var list = container.Products.Where(c=>c.Id==).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(); }