【问题标题】:Breeze & OData: Trouble expanding a collectionBreeze & OData:无法扩展集合
【发布时间】:2013-05-16 23:51:51
【问题描述】:

什么有效:

在 Breeze 中我可以执行这个查询:

第一季度

breeze.EntityQuery.from('accounts').where('id', 'eq', account_id)

导致此请求:

R1

http://localhost:8000/odata/findash.svc/accounts
    ?$filter=id eq 'NTE5M2UxMzQzMmY3MDAxYzE1MDAwMDAx'

它返回正确的数据,只是 transactions 属性如下所示:

transactions: {
    __deferred: {
        uri: "http://localhost:8000/odata/findash.svc/accounts('NTE5M2UxMzQzMmY3MDAxYzE1MDAwMDAx')/transactions"
    }
}

我尝试在浏览器中点击 transactions.__deferred.uri 的 URI

R1.1

http://localhost:8000/odata/findash.svc/
    accounts('NTE5M2UxMzQzMmY3MDAxYzE1MDAwMDAx')/transactions

它确实响应了我期望的交易。

什么不起作用:

为了尝试通过 Breeze 获取该事务列表,我使用如下所示的扩展子句更改上述查询:

第二季度

breeze.EntityQuery.from('accounts')
    .where('id', 'eq', account_id).expand('transactions')

导致此请求:

R2

http://localhost:8000/odata/findash.svc/accounts
    ?$filter=id eq 'NTE5M2UxMzQzMmY3MDAxYzE1MDAwMDAx'&$expand=transactions

会产生 500 错误。

我也试过这个微风查询:

第三季度

breeze.EntityQuery.from('transactions')
    .expand('account').where('account.id', 'eq', account_id)

这也会产生 500 错误。

我需要知道的:

在深入了解基于 Node+MongoDB+JayData 构建的 OData 服务之前,我试图排除 Breeze。

上面 R1 和 R2 的唯一区别是添加了&$expand=transactions。 R1 工作,R2 导致 500 错误。如果 R2 是一个有效的 OData 请求,那么我需要将我的故障排除工作集中在我的 JayData 实施上。对我来说,麻烦在于我是 Breeze、OData 和 JayData 的新手,所以我无法缩小搜索范围。

作为参考,我的 JayData context.js 在这里:

$data.Class.define("$findash.Types.Account", $data.Entity, null, {
    id: { type: "id", key: true, computed: true },
    name: { type: "string" },
    status: { type: "string" },
    notes: { type: "string" },
    transactions: { type: "Array", elementType: "$findash.Types.Transaction", inverseProperty: "account" }
}, null);
$data.Class.define("$findash.Types.Transaction", $data.Entity, null, {
    id: { type: "id", key: true, computed: true },
    account: { type: "$findash.Types.Account", inverseProperty: "transactions" },
    payee: { type: "string" },
    memo: { type: "string" },
    amount: { type: "int" }
}, null);
$data.Class.define("$findash.Types.FinanceContext", $data.EntityContext, null, {
    accounts: { type: $data.EntitySet, elementType: $findash.Types.Account },
    transactions: { type: $data.EntitySet, elementType: $findash.Types.Transaction }
}, null);
$findash.Types.FinanceContext.generateTestData = function (context, callBack) {
    context.accounts.add(new $findash.Types.Account({
        name: 'Checking',
        status: 'Active',
        notes: '<p>Notes lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus mauris quam, elementum in tincidunt id, mollis eget urna. Nulla fermentum est id risus venenatis malesuada. Quisque sed ipsum at nisl malesuada dictum vitae nec libero.</p><p>Aenean consectetur, purus eu semper feugiat, purus lacus semper nibh, at luctus ipsum metus non justo. Donec justo mi, rutrum a scelerisque sed, feugiat vel quam. Etiam justo nisi, vehicula ac congue vitae, ultricies non quam. Aliquam a velit in mauris luctus elementum. Praesent sollicitudin quam mattis velit sodales vitae feugiat felis volutpat.</p>',
        transactions: [
            new $findash.Types.Transaction({
                payee: 'Shell Gas',
                memo: 'Checkcard Transaction',
                amount: -3500
            }),
            new $findash.Types.Transaction({
                payee: 'Kroger',
                memo: 'Checkcard Transaction',
                amount: -9000
            }),
            new $findash.Types.Transaction({
                payee: 'Papa Murphy\'s',
                memo: 'Checkcard Transaction',
                amount: -1500
            })
        ]
    }));
    context.accounts.add(new $findash.Types.Account({
        name: 'Savings'
    }));
    context.accounts.add(new $findash.Types.Account({
        name: 'Power Company'
    }));
    context.accounts.add(new $findash.Types.Account({
        name: 'Gas Company'
    }));
    context.accounts.add(new $findash.Types.Account({
        name: 'Cable Company'
    }));
    context.accounts.add(new $findash.Types.Account({
        name: 'Water Company'
    }));
    context.accounts.add(new $findash.Types.Account({
        name: 'Trash Service'
    }));
    context.saveChanges(function (count) {
        if (callBack) {
            callBack(count);
        }
    });
};
module.exports = exports = $findash.Types.FinanceContext;

【问题讨论】:

    标签: odata breeze jaydata


    【解决方案1】:

    您能否发布服务器端模型相关部分的代码?这看起来像是模型定义的服务器端问题,或者它是如何通过 OData 公开的。

    真正的测试是尝试在不涉及 Breeze 的情况下访问 OData 服务。我猜你会得到同样的错误。如果不是,那么这是一个 Breeze 错误。如果是这样,那么您需要查看您的 OData 服务。

    【讨论】:

    • 您是否尝试过不使用 Breeze 的 OData 调用?您确定 JayData 支持 OData“扩展”吗?
    • 嗨,我来自 JayStack,JayData 的创建者。 JayData Server 仅支持使用 Pro mongodb 驱动程序进行扩展。 Pro 驱动程序可免费用于非商业用途,付费软件可用于商业用途。它的价格为 250 美元,但提供了其他不错的功能,不仅是导航,还包括地理搜索、索引处理和专业支持。
    • 抱歉,信息有误!! expand 也适用于免费版本,但您必须使用最新版本 (1.3)
    猜你喜欢
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 2014-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-17
    • 2017-07-06
    相关资源
    最近更新 更多