0

什么有效:

在 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 获取该事务列表,我使用如下所示的 expand 子句更改上述查询:

第二季度

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;
4

1 回答 1

0

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

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

于 2013-05-15T20:50:53.777 回答