Breeze / breeze.server.net

Breeze support for .NET servers
MIT License
76 stars 62 forks source link

inlineCount() does not work when is used alone #129

Closed buchatsky closed 2 years ago

buchatsky commented 2 years ago

Requests to the Web API controller (derived from ControllerBase) with [BreezeQueryFilter] and with the single {"inlineCount":true} option in QueryString always return a plain data array without a surrounding Breeze context:

    const query = new EntityQuery('Customers').inlineCount();
    this.manager.executeQuery(query).then(qr => {
      this.customers = qr.results;
      var cnt = qr.inlineCount; // always undefined
    });

Requests with inlineCount used along with any other QueryFilter option work as expected and return the correct Breeze context (with its Results set to data array and InlineCount set to correct count):

    const query = new EntityQuery('Customers').where('lastName', 'startsWith', 'C').inlineCount();
    this.manager.executeQuery(query).then(qr => {
      this.customers = qr.results;
      var cnt = qr.inlineCount; // correct number
    });

.Net 5 Breeze.AspNetCore.NetCore: 5.0.5

steveschmitt commented 2 years ago

Thanks for reporting this. We'll take a look.

marcelgood commented 2 years ago

Pretty sure this is because you are missing skip or take. No point to have an inline count if you are returning the entire resultset. Just count the returned entities. I'm using inlineCount in my current project and it's returning the count just fine, but I have at least a take.

This works fine for pagination:

entityQuery
    .skip(currentPage.pageIndex * (currentPage.pageSize || pageSize))
    .take(currentPage.pageSize || pageSize)
    .inlineCount(),

and this works fine if you just wanna count the records, but not actually returning them:

entityQuery.take(0).inlineCount()
buchatsky commented 2 years ago

@marcelgood I agree with you, thank you. So, it's a feature, not a bug