Reputation: 473
When I call inlineCount() on a query that both orders by a related property and performs a take on the query, the inlineCount is equal to the argument passed to take(). For example, the following query returns the correct inlineCount:
testFunc = function () {
EntityQuery.from('Residents')
.take(10)
.inlineCount()
.using(manager).execute()
.then(function (data) {
console.log(data.inlineCount, data); //logs correct value
});
}
But the when I add ordering to my query as follows:
testFuncOrdering = function () {
EntityQuery.from('Residents')
.orderBy('user.firstName')
.take(10)
.inlineCount()
.using(manager).execute()
.then(function (data) {
console.log(data.inlineCount, data); //logs 10
});
}
The inlineCount is 10, or whatever I pass to take
Here's my controller action:
[HttpGet]
public IQueryable<UserDetail> Residents()
{
return _context.Context.UserDetails
.Where(x => _aptIds.Contains(x.User.UserDetail.ApartmentComplexId))
.Where(x => x.Discriminator == UserDetail.Resident);
}
This bug seems similar to a bug that was fixed in 1.4.0, but instead of getting null/undefined for inlineCount, I'm getting the take value. If necessary, I can provide my metadata. Any help is appreciated, thanks.
Upvotes: 1
Views: 645
Reputation: 17863
I have confirmed your finding and reported internally as Defect #2493. Here is my repro:
First, we know inlineCount
works with orderBy
and take
at least some of the time. Here is a test from DocCode that passes:
var productQuery = EntityQuery.from("Products" .where("ProductName", "startsWith", "C"); var pagedQuery = productQuery .orderBy("ProductName") .skip(5) .take(5) .inlineCount();
The JSON result is:
{ $id: "1", $type: "Breeze.WebApi.QueryResult, Breeze.WebApi", Results: [ {...}, {...}, {...}, {...}, ], InlineCount: 9 }
Four products returned out a total of 9 products with names that begin with 'C'. Yes it still works without the .skip(5)
; it returns the first 5 products and again reports a total of 9 qualifying products.
Here is the generated URL for that query:
http://localhost:47595/breeze/Northwind/Products?$filter=startswith(ProductName,'C') eq true&$orderby=ProductName&$top=5&$inlinecount=allpages
So we know Breeze does the right thing at least some of the time :)
What is going wrong for you?
It seems that the problem is with an orderBy
on a related entity property (e.g., your "user.firstName").
Returning to DocCode, I revised the query URL to get OrderDetails
, sorted by their related Product.ProductNames
. I didn't bother with composing the breeze query. I simply entered the generated URL into the browser address bar.
Here is the URL with the orderBy:
http://localhost:47595/breeze/Northwind/OrderDetails?$orderby=Product/ProductName&$top=5&$inlinecount=allpages
The resulting inlineCount
is 5 ... the take
value and the number of records actually returned.
And when I remove the orderBy
:
http://localhost:47595/breeze/Northwind/OrderDetails?$top=5&$inlinecount=allpages
Again we get 5 OrderDetails but the resulting inlineCount
is 2155 !!!
Houston, we have a problem.
Upvotes: 3