问题
I'm doing a query:
var query = entityQuery.from('Items').where(fullPredicate).orderBy(sortingColumn + ' ' + ordering).skip(numOfEntities * (pageNum - 1)).take(numOfEntities).inlineCount();
return manager.executeQuery(query)
.then(querySucceeded)
.fail(queryFailed);
Controller looks like this:
[Queryable(AllowedQueryOptions = AllowedQueryOptions.All,
AllowedFunctions = AllowedFunctions.AllFunctions,
MaxNodeCount = 10000)]
[HttpGet]
public IQueryable<Item> Items()
{
return _contextProvider.Context.Items.Include("A").Include("B").Include("C");
}
Response is pure JSON with all Items and linked (Included) items (A, B and C), but without inlineCount. While reading data in querySucceeded, there is a parameter called inlineCount but is set to undefined.
I've tried adding the following to web.config, but it didn't help.
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
<add name="Access-Control-Allow-Methods" value="GET,POST,OPTIONS" />
<add name="Access-Control-Expose-Headers" value="X-InlineCount" />
</customHeaders>
</httpProtocol>
Upgraded from 1.4.0 to 1.4.2 as well, but didn't help.
回答1:
I finally got my server to respond with correct inlinecount value using Breeze.js client and Breeze Web Api server control (BreezeController).
You need to add the attribute BreezeQueryable instead of the standard OData Queryable. The inlinecount will not be included in the server response by the Breeze controller, unless you include this attribute above your method.
So the following server code resolved my issue:
[HttpGet, BreezeQueryable]
public IQueryable<FinDataModelsPublic.InvoicesView> InvoicesView(ODataQueryOptions<FinDataModelsPublic.InvoicesView> options, int custId)
{
return FBll.InvoicesView(custId);
}
Above the Bll.InvoicesView is a method from my data model returning IQueryable result.
Hope this helps
回答2:
Removing the following solved the problem. There is probably a bug where inlineCount is not included in AllFunctions or something.
[Queryable(AllowedQueryOptions = AllowedQueryOptions.All,
AllowedFunctions = AllowedFunctions.AllFunctions,
MaxNodeCount = 10000)]
来源:https://stackoverflow.com/questions/18891823/breeze-inlinecount-is-undefined