【问题标题】:Breezejs error with take(), orderBy, and inlineCountBreezejs 错误与 take()、orderBy 和 inlineCount
【发布时间】:2013-08-14 07:34:43
【问题描述】:

当我对一个查询调用 inlineCount() 时,该查询既按相关属性排序,又对查询执行 take,inlineCount 等于传递给 take() 的参数。例如,以下查询返回正确的 inlineCount:

    testFunc = function () {
        EntityQuery.from('Residents')                    
                .take(10)                    
                .inlineCount()
                .using(manager).execute()
                .then(function (data) {
                    console.log(data.inlineCount, data);  //logs correct value                      
                });
    }

但是当我按如下方式向查询中添加排序时:

testFuncOrdering = function () {
    EntityQuery.from('Residents')
            .orderBy('user.firstName')
            .take(10)
            .inlineCount()
            .using(manager).execute()
            .then(function (data) {
                console.log(data.inlineCount, data); //logs 10
            });
}

inlineCount 是 10,或者我传递的任何值

这是我的控制器操作:

[HttpGet]
public IQueryable<UserDetail> Residents()
{
    return _context.Context.UserDetails
        .Where(x => _aptIds.Contains(x.User.UserDetail.ApartmentComplexId))
        .Where(x => x.Discriminator == UserDetail.Resident);
}     

这个错误似乎与 1.4.0 中修复的错误相似,但我得到的不是 inlineCount 的 null/undefined,而是取值。如有必要,我可以提供我的元数据。任何帮助表示赞赏,谢谢。

【问题讨论】:

    标签: breeze


    【解决方案1】:

    我已确认您的发现并在内部报告为缺陷 #2493。这是我的再现:

    首先,我们知道inlineCount 至少在某些时候可以与orderBytake 一起使用。这是来自 DocCode 的一个通过的测试:

    var productQuery = EntityQuery.from("产品" .where("ProductName", "startsWith", "C"); var pagedQuery = productQuery .orderBy("产品名称") .skip(5) .take(5) .inlineCount();

    JSON 结果是:

    { $id:“1”, $type: "Breeze.WebApi.QueryResult, Breeze.WebApi", 结果: [ {...}, {...}, {...}, {...}, ], 内联数:9 }

    四个产品返回了总共 9 个名称以“C”开头的产品。是的,没有.skip(5),它仍然可以工作;它返回前 5 个产品,然后再次报告总共 9 个合格产品。

    这是为该查询生成的 URL:

    http://localhost:47595/breeze/Northwind/Products?$filter=startswith(ProductName,'C') eq true&$orderby=ProductName&$top=5&$inlinecount=allpages

    所以我们知道 Breeze 至少在某些时候会做正确的事 :)

    你怎么了?

    问题似乎在于相关实体属性上的orderBy(例如,您的“user.firstName”)。

    回到 DocCode,我修改了查询 URL 以获取 OrderDetails,并按相关的 Product.ProductNames 排序。我没有费心编写微风查询。我只是将生成的 URL 输入到浏览器地址栏中。

    这是带有 orderBy 的 URL:

    http://localhost:47595/breeze/Northwind/OrderDetails?$orderby=Product/ProductName&$top=5&$inlinecount=allpages

    生成的inlineCount5 ...take 值和实际返回的记录数。

    当我删除orderBy:

    http://localhost:47595/breeze/Northwind/OrderDetails?$top=5&$inlinecount=allpages

    我们再次得到 5 个 OrderDetails,但结果 inlineCount2155 !!!

    休斯顿,我们有问题。

    【讨论】:

      【解决方案2】:

      此问题已在 Breeze v 1.4.1 中得到修复,现在可用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-08-29
        • 2018-12-16
        • 2019-01-24
        • 1970-01-01
        • 2011-07-16
        • 2021-12-16
        • 2018-02-03
        相关资源
        最近更新 更多