Why are there missing client-side results when using OData options with Entity Framework DBContext?

拜拜、爱过 提交于 2019-12-02 11:29:05

You don't mix and match QueryableAttribute and ODataQueryOptions<T>. Pick one depending on whether you want manual control over applying the query options (ODataQueryOptions<T>) or make it happen automatically (QueryableAttribute).

You have two options,

public IEnumerable<USER> Get(ODataQueryOptions<USER> options)
{
    var dbContext = new ATMS.DAL.AtmsContext();
    var ret = options.ApplyTo(dbContext.USERS).Cast<USER>();
    return ret;
}

or

[Queryable]
public IEnumerable<USER> Get(ODataQueryOptions<USER> options)
{
    var dbContext = new ATMS.DAL.AtmsContext();
    var ret = dbContext.USERS;
    return ret;
}

The reason you are seeing that behavior is that you are applying the query twice, once using ODataQueryOptions<T>.ApplyTo and then again through QueryableAttribute.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!