我正在尝试使用 Durandal、Breeze 和淘汰赛来实现 WebApi OData。但我总是低于错误:
无法初始化 OData。需要支持远程 OData 服务
我创建了一个视图模型:
var my = {}; //my namespace
$(function () {
var serverAddress = "/odata/";
breeze.config.initializeAdapterInstances({ dataService: "OData" });
var manager = new breeze.EntityManager(serverAddress);
my.vm = {
customers: ko.observableArray([]),
load: function () {
var query = breeze.EntityQuery.from("Customers");
manager.executeQuery(query, function (data) {
var results = data.results;
$.each(data.results, function (i, c) {
my.vm.customers.push(c);
});
});
}
}
my.vm.load();
ko.applyBindings(my.vm);
});
在 BreezWebApiConfig 中提到:
public static void RegisterBreezePreStart() {
GlobalConfiguration.Configuration.Routes.MapHttpRoute(
name: "BreezeApi",
routeTemplate: "api/{controller}/{action}"
);
}
并注册了 WebApi :
public static void Register(HttpConfiguration config)
{
config.Routes.MapODataRoute("odata", "odata", GetEdmModel());
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
如果有人有这个想法,请建议我。