Exception 查询返回数据时出现错误(更新:元数据未正确加载)

Exception 查询返回数据时出现错误(更新:元数据未正确加载),exception,odata,breeze,Exception,Odata,Breeze,我使用ODataController将数据返回到breeze数据服务,这就是数据服务 app.dataservice = (function (breeze) { breeze.config.initializeAdapterInstances({ dataService: "OData" }); var manager = new breeze.EntityManager('/api/v1/'); return { getRecipePage

我使用ODataController将数据返回到breeze数据服务,这就是数据服务

app.dataservice = (function (breeze) {    
    breeze.config.initializeAdapterInstances({ dataService: "OData" });

    var manager = new breeze.EntityManager('/api/v1/');

    return {
        getRecipePage: getRecipePage
    };

    function getRecipePage(skip, take, searchText) {
        var query = breeze.EntityQuery
                .from("Recipes")
                .orderBy("Name")
                .skip(skip).take(take)
                .inlineCount(true);
        if (searchText) {
            query = query.where("Name", "contains", searchText);
        }

        return manager.executeQuery(query);
    }
})(breeze);
在我的控制器中调用getRecipePage函数时,它似乎正确地返回数据,但异常情况很奇怪

getDataFunction(skip, take)
        .then(function (largeLoad) {
            $scope.setPagedData(largeLoad, currentPage, pageSize);
        })
        .fail(function (e) {
            debugger;
        });
e变量有消息
“;”
,这毫无意义。状态为“200 OK”,这很好

正文包含我的两个实体,url显示正确“/api/v1/Recipes?$orderby=Name&$top=2&$inlinecount=allpages”,如果我导航到它,json看起来很好:

{
    "$id": "1",
    "$type": "Breeze.WebApi2.QueryResult, Breeze.WebApi2",
    "Results": [
        {
            "$id": "2",
            "$type": "RecipeBook.Web.Angular.Models.RecipeBook.Recipe, RecipeBook.Web.Angular",
            "Name": "1 Boiled Water",
            "Description": "6 Steamy goodness!",
            "Id": 1
        },
        {
            "$id": "3",
            "$type": "RecipeBook.Web.Angular.Models.RecipeBook.Recipe, RecipeBook.Web.Angular",
            "Name": "2 Hot Chocolate",
            "Description": "5 Chocolatey Chocolateness!",
            "Id": 2
        }
    ],
    "InlineCount": 6
}
…这是什么错误?最后,这里是堆栈:

Error
    at createError (http://localhost:62576/Scripts/breeze.debug.js:15182:22)
    at http://localhost:62576/Scripts/breeze.debug.js:14971:40
    at http://localhost:62576/Scripts/datajs-1.1.1.js:1671:17
    at XMLHttpRequest.odata.defaultHttpClient.request.xhr.onreadystatechange (http://localhost:62576/Scripts/datajs-1.1.1.js:2587:25)
关于发生了什么的想法

编辑: 经过大量的挖掘,我已经将问题缩小到与读取响应的处理程序相关的范围。在datajs-1.1.1.js~第8100行中有一个dispatchHandler函数。我有一个从OData呼叫返回的请求者响应:

它有一个带有上述json文本的body属性。然而,数据属性尚未定义,但我认为这正是它试图将主体转换成的内容……并且正在寻找一个处理程序来实现这一点。它的状态代码是200,状态文本是OK。但该方法未找到适当的处理程序并抛出:

  throw { message: "no handler for data" };
…这似乎是错误产生的地方。我只是不知道什么设置不正确,所以我可以补救这种情况

EDIT2: 这实际上可能是因为元数据(xml)没有被正确解析而导致的…,这就是它的样子(取自调试时的datajs handlerRead函数)


看起来您正在使用Web API。考虑你可以用<代码> [MyZeCaldReals] 属性来装饰控制器,而不是指定<代码> ODATAs/COD> >可以使用<代码> WebAPI < /Cord>,这有点扩展了配置。值得一试

此外,您可能需要配置Breeze适配器以使用backingStore,它与Angular很好地匹配(此链接提供了一些有用的提示,可以指导您如何设置微风,以便与Angular一起工作)

最后,请记住,第一次使用任何库时设置它似乎总是比实际困难。一旦你把它配置好,你几乎再也不会碰配置了,取而代之的是Breeze可以正常工作,非常棒

编辑

检查此链接,该链接简要介绍了Breeze、Angular、OData和Web API-

另一个很好的“我该怎么做…”回答这里的沃德-


在Breeze之前,您是否包含Data.js?也可以考虑使用布瑞恩诺伊斯的ODATA步道来设置Breeze.js -是的,我用它作为参考,我是如何使它工作到目前为止,但是我不能精确地复制它,因为我们不使用EF。@ PWKad,我们使用角不KO,当我尝试在Odata服务上使用BreezeSimpleCorsHandler时,我也遇到了同样的错误。当请求数据“跨域”时,它会由于这个神秘的错误而失败,但是如果我从localhost请求数据,它可以正常工作。我知道它似乎不适用于这个问题,但我觉得它很有趣。我使用的是BreezeController属性。我习惯于在新图书馆里“出牙”,不用担心。如何配置breeze使用backingStore,我有
breeze.config.initializeAdapterInstance(“modelLibrary”,“backingStore”,true)
,但删除了它,因为我似乎无法将它与
breeze.config.initializedapterninstances({dataService:“OData”})合并行?事实上,如果我把这两行放在一起,我会得到与上面所述相同的错误。这些似乎都没有帮助。我从服务返回数据…它只是点击
.fail()
,而不是
。然后()
,并显示错误消息
“;”
,这没有任何意义,即使错误('e')正文包含我的OData服务返回的实体。我编辑了这个问题,并提供了有关异常根源的更多信息。
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
  <edmx:DataServices m:DataServiceVersion="3.0" m:MaxDataServiceVersion="3.0" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
    <Schema Namespace="RecipeBook.Web.Angular.Models.Recipe" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
      <EntityType Name="Recipe">
        <Key>
          <PropertyRef Name="Id" />
        </Key>
        <Property Name="Id" Type="Edm.Int32" Nullable="false" />
        <Property Name="Name" Type="Edm.String" />
        <Property Name="Description" Type="Edm.String" />
        <Property Name="Steps" Type="Collection(Edm.String)" />
        <NavigationProperty Name="Ingredients" Relationship="RecipeBook.Web.Angular.Models.Recipe.RecipeBook_Web_Angular_Models_Recipe_Recipe_Ingredients_RecipeBook_Web_Angular_Models_Recipe_RecipeIngredient_IngredientsPartner" ToRole="Ingredients" FromRole="IngredientsPartner" />
      </EntityType>
      <EntityType Name="RecipeIngredient">
        <Key>
          <PropertyRef Name="Id" />
        </Key>
        <Property Name="Id" Type="Edm.Int32" Nullable="false" />
        <Property Name="IngredientId" Type="Edm.Int32" Nullable="false" />
        <Property Name="Quantity" Type="Edm.Int32" Nullable="false" />
        <Property Name="UnitOfMeasureId" Type="Edm.Int32" Nullable="false" />
        <Property Name="Notes" Type="Edm.String" />
      </EntityType>
      <Association Name="RecipeBook_Web_Angular_Models_Recipe_Recipe_Ingredients_RecipeBook_Web_Angular_Models_Recipe_RecipeIngredient_IngredientsPartner">
        <End Type="RecipeBook.Web.Angular.Models.Recipe.RecipeIngredient" Role="Ingredients" Multiplicity="*" />
        <End Type="RecipeBook.Web.Angular.Models.Recipe.Recipe" Role="IngredientsPartner" Multiplicity="0..1" />
      </Association>
      <EntityContainer Name="Container" m:IsDefaultEntityContainer="true">
        <EntitySet Name="Recipes" EntityType="RecipeBook.Web.Angular.Models.Recipe.Recipe" />
      </EntityContainer>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>
var dataService = new breeze.DataService({
    serviceName: "/api/v1/",
    hasServerMetadata: false 
});