查看edmx:http://localhost:12769/odata/$metadata
1.配置
ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); builder.EntitySet<CNPC.IMS.Model.tbl_Base_User>("tbl_Base_User"); builder.EntitySet<CNPC.IMS.Model.tbl_Base_OUInfoView>("tbl_Base_OUInfoView"); ActionConfiguration rateProduct = builder.Entity<tbl_Base_OUInfoView>().Action("RateProduct"); rateProduct.Parameter<int>("Rating"); rateProduct.Parameter<string>("Rating2"); rateProduct.Parameter<System.Guid>("OUID"); rateProduct.Parameter<string>("UserID"); config.Routes.MapODataServiceRoute("odata", "odata", builder.GetEdmModel());
2.控制器方法
[HttpPost] public HttpResponseMessage RateProduct(ODataActionParameters parameters) { try { //Tbl_Base_UserBLL.Post(tbl_Base_User); object Rating = parameters["Rating"]; object Rating2 = parameters["Rating2"]; object OUID = parameters["OUID"]; object UserID = parameters["UserID"]; return Common.JsonHelper.toJson(new { message = "ok" }); } catch (Exception e) { return Common.JsonHelper.toJson(new { message = "fail" }); } }
3.请求(最后一个参数可以省,否则接不到参数)
地址:http://localhost:12769/odata/tbl_Base_OUInfoView(183585F1-45F1-4043-A619-628AFA90BFD4)/RateProduct 类型:POST 参数: { {"Rating":2,"Rating2":"34","OUID":"183585F1-45F1-4043-A619-628AFA90BFD4","UserID":"183585F1-45F1-4043-A619-628AFA90BFD4"} }