【问题标题】:confused between Api Controller and oData Controller to use with angular's ngresource在 Api Controller 和 oData Controller 与 Angular 的 ngresource 一起使用时感到困惑
【发布时间】:2015-05-30 00:33:56
【问题描述】:

我有一个调用 web api 的 Angular 应用程序。在我需要计算结果之前,它可以与 web api 控制器和 ngresource 一起正常工作。

要获得结果的计数,我需要使用 $inlinecount ,它似乎只与 oDataController 一起使用。有了 oDataControlelr,我的承诺就不起作用了。

$scope.totalCount = storeCommandResource.query({ $inlinecount: "allpages", $top: 0 });

我明白了

Error: [$resource:badcfg] query

请指导。

【问题讨论】:

标签: angularjs ngresource asp.net-web-api-odata


【解决方案1】:

看起来我可以将 oDatacontroller 与这样的模型构建器设置一起使用

            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
        builder.EntitySet<StoreCommand>("StoreCommandsRest");
        config.Routes.MapODataServiceRoute(routeName: "OData", routePrefix: "api", model: builder.GetEdmModel());
        config.AddODataQueryFilter();

我需要改变的只是查询来获取

$scope.totalCount = storeCommandResource.get({ $inlinecount: "allpages", $top: 0 });

然后我正在阅读我返回的计数,例如

response["odata.count"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-17
    • 1970-01-01
    • 1970-01-01
    • 2012-06-28
    • 2018-12-05
    • 2014-02-14
    • 1970-01-01
    相关资源
    最近更新 更多