ASP.NET ODataQueryOptions设置默认值

时间:2018-11-20 16:14:44

标签: .net-core odata

我想为ODataQueryOptions“打开” $ count = true。这是我的代码:

[HttpGet]
[Route("")]
public async Task<ActionResult<PageResult<DTO.contact>>> GetAllAsync(

    [FromQuery]Microsoft.AspNet.OData.Query.ODataQueryOptions<DTO.contact> options = null
)
{
    var _query = this.IUnitOfWork.IDataRepository.contacts

                        .Where(w => w.org_id == config_org_id)

                        .UseAsDataSource(this.IMapper.ConfigurationProvider)
                        .For<DTO.contact>()

                        .AsQueryable()
                        ;

    var _query = options.Apply(_query) as IQueryable<DTO.contact>;

    long? _total = null;

    _total = options.Request.HttpContext.ODataFeature().TotalCount;

    return new PageResult<DTO.contact>() {
            total = _total,
            entities = _query.ToArray()
    };

}

除非未在URL中指定$ count = true,否则不会计算TotalCount。

如何默认情况下如何“打开” $ count,这样我就不必在每个请求中都指定它?

谢谢!

0 个答案:

没有答案