Asp.net web api 使用WebAPI 2.0时获取筛选器错误

Asp.net web api 使用WebAPI 2.0时获取筛选器错误,asp.net-web-api,webapp2,asp.net-web-api2,Asp.net Web Api,Webapp2,Asp.net Web Api2,对于下面的REST查询,我得到了一个错误。(它对于分页/排序很有效) 如何修复此错误 http://localhost:18376/api/Org/GetOrgHeadQuarter?%24inlinecount=allpages&%24top=2&%24filter=Name+eq+%27test%27 下面是WebAPI 2.1方法 public PageResult<dynamic> GetOrgHeadQuarter(ODataQueryOptions op

对于下面的REST查询,我得到了一个错误。(它对于分页/排序很有效) 如何修复此错误

http://localhost:18376/api/Org/GetOrgHeadQuarter?%24inlinecount=allpages&%24top=2&%24filter=Name+eq+%27test%27
下面是WebAPI 2.1方法

public PageResult<dynamic> GetOrgHeadQuarter(ODataQueryOptions options)
    {
        try
        {


            IQueryable results = options.ApplyTo(db.OrgHeadQuarters
                                   .Select(os => new 
                                   {
                                       ROWID = os.ROWID,
                                       OrgHeadCode_PK = os.OrgHeadCode_PK,
                                       Code = os.Code,
                                       Name = os.Name,
                                       Description = os.Description,
                                       Address1 = os.Address1,
                                       Address2 = os.Address2,
                                       CountryCode_FK = os.CountryCode_FK,
                                       EffectiveDate = os.EffectiveDate,
                                       TerminationDate = os.TerminationDate,
                                       DateCreated = os.DateCreated,
                                       DateUpdated = os.DateUpdated,
                                       CreatedByUserID_FK = os.CreatedByUserID_FK,
                                       UpdatedByUserID_FK = os.UpdatedByUserID_FK,
                                       CountryName = os.Country.CountryName,
                                       StateCode_FK = os.StateCode_FK,
                                       StateName = os.State.StateName,
                                       CityCode_FK = os.CityCode_FK,
                                       CityName = os.City.CityName,
                                       ZIP = os.ZIP,
                                       RowStatusID_FK = os.RowStatusCode_FK,
                                       RowStatusName = os.RowStatus.Name,
                                       CreatedByUserName = os.CreatedByUser.UserName,
                                       UpdatedByUserName = os.UpdatedByUser.UserName
                                   }).OrderBy(o => o.OrgHeadCode_PK));


        return new PageResult<dynamic>(
            results as IEnumerable<dynamic>,
            Request.GetNextPageLink(),
            Request.GetInlineCount());

        }
        catch (Exception e)
        {
            throw;
        }
    }
public页面结果GetOrgHeadquarters(ODataQueryOptions选项)
{
尝试
{
IQueryable结果=options.ApplyTo(db.org)
.选择(操作系统=>新建)
{
ROWID=os.ROWID,
OrgHeadCode_PK=os.OrgHeadCode_PK,
代码=操作系统代码,
Name=os.Name,
Description=os.Description,
Address1=os.Address1,
Address2=os.Address2,
CountryCode_FK=os.CountryCode_FK,
EffectiveDate=os.EffectiveDate,
TerminationDate=os.TerminationDate,
DateCreated=os.DateCreated,
DateUpdated=os.DateUpdated,
CreatedByUserID_FK=os.CreatedByUserID_FK,
UpdatedByUserID\u FK=os.UpdatedByUserID\u FK,
CountryName=os.Country.CountryName,
StateCode_FK=os.StateCode_FK,
StateName=os.State.StateName,
CityCode_FK=os.CityCode_FK,
CityName=os.City.CityName,
ZIP=os.ZIP,
RowStatusID\u FK=os.RowStatusCode\u FK,
RowStatusName=os.RowStatus.Name,
CreatedByUserName=os.CreatedByUserName.UserName,
UpdatedByUserName=os.UpdatedByUser.UserName
}).OrderBy(o=>o.OrgHeadCode_PK));
返回新页面结果(
结果是不可数的,
Request.GetNextPageLink(),
Request.GetInlineCount());
}
捕获(例外e)
{
投掷;
}
}
这就是我得到的错误

{ "Message": "An error has occurred.", "ExceptionMessage": "Could not find a property named 'Name' on type 'System.Object'.", "ExceptionType": "Microsoft.Data.OData.ODataException", "StackTrace": " at Microsoft.Data.OData.Query.EndPathBinder.GeneratePropertyAccessQueryForOpenType(EndPathToken endPathToken, SingleValueNode parentNode)\r\n at Microsoft.Data.OData.Query.EndPathBinder.BindEndPath(EndPathToken endPathToken, BindingState state)\r\n at Microsoft.Data.OData.Query.MetadataBinder.BindEndPath(EndPathToken endPathToken)\r\n at Microsoft.Data.OData.Query.MetadataBinder.Bind(QueryToken token)\r\n at Microsoft.Data.OData.Query.BinaryOperatorBinder.GetOperandFromToken(BinaryOperatorKind operatorKind, QueryToken queryToken)\r\n at Microsoft.Data.OData.Query.BinaryOperatorBinder.BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)\r\n at Microsoft.Data.OData.Query.MetadataBinder.BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)\r\n at Microsoft.Data.OData.Query.MetadataBinder.Bind(QueryToken token)\r\n at Microsoft.Data.OData.Query.FilterBinder.BindFilter(QueryToken filter)\r\n at Microsoft.Data.OData.Query.ODataUriParser.ParseFilterImplementation(String filter, IEdmType elementType, IEdmEntitySet entitySet)\r\n at Microsoft.Data.OData.Query.ODataUriParser.ParseFilter(String filter, IEdmType elementType, IEdmEntitySet entitySet)\r\n at Microsoft.Data.OData.Query.ODataUriParser.ParseFilter(String filter, IEdmModel model, IEdmType elementType)\r\n at System.Web.Http.OData.Query.FilterQueryOption.get_FilterClause()\r\n at System.Web.Http.OData.Query.FilterQueryOption.ApplyTo(IQueryable query, ODataQuerySettings querySettings, IAssembliesResolver assembliesResolver)\r\n at System.Web.Http.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings)\r\n at System.Web.Http.OData.Query.ODataQueryOptions`1.ApplyTo(IQueryable query, ODataQuerySettings querySettings)\r\n at System.Web.Http.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query)\r\n at System.Web.Http.OData.Query.ODataQueryOptions`1.ApplyTo(IQueryable query)\r\n at SchoolManagement.HTML5.Controllers.OrgController.GetOrgHeadQuarter(ODataQueryOptions options) in c:\\Projects\\AuthProj\\Controllers\\OrgController.cs:line 160\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Filters.AuthorizationFilterAttribute.d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.AuthenticationFilterResult.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__0.MoveNext()" }`enter code here`
{“消息”:“出现错误。”,“异常消息”:“在类型“System.Object.”上找不到名为“Name”的属性”,“异常类型”:“Microsoft.Data.OData.ODataException”,“StackTrace”:“在Microsoft.Data.OData.Query.EndPathBinder.GeneratePropertyAccessQueryForOpenType(EndPathToken EndPathToken,SingleValueNode parentNode)\r\n位于Microsoft.Data.OData.Query.EndPathBinder.BindPath(EndPathToken EndPathToken,BindingState)\r\n位于Microsoft.Data.OData.Query.MetadataBinder.BindPathToken(EndPathToken EndPathToken)Microsoft.Data.OData.Query.MetadataBinder.Bind(QueryToken)Microsoft.Data.OData.Query.BinaryOperatorBinder.GetOperatorFromToken(BinaryOperatorKind operatorKind,QueryToken QueryToken)\r\n位于Microsoft.Data.OData.Query.BinaryOperatorBinder.BindbaryOperator(BinaryOperatorToken BinaryOperatorToken)的Microsoft.Data.OData.Query.MetadataBinder.BindbaryOperator(BinaryOperatorToken BinaryOperator)的Microsoft.Data.OData.Query.MetadataBinder\r\n(QueryToken标记)\r\n位于Microsoft.Data.OData.Query.FilterBinder.BindFilter(QueryToken筛选器)\r\n位于Microsoft.Data.OData.Query.ODataUriParser.ParseFilterImplementation(字符串筛选器、IEdmType elementType、IEdmEntitySet entitySet)\r\n位于Microsoft.Data.OData.Query.ODataUriParser.ParseFilter(字符串筛选器,IEdmType elementType,IEdmEntitySet entitySet)\r\n位于Microsoft.Data.OData.Query.ODataUriParser.ParseFilter(字符串筛选器,IEdmModel模型,IEdmType elementType)\r\n位于System.Web.Http.OData.Query.FilterQueryOption.get\u FilterClause()\r\n位于System.Web.Http.OData.Query.FilterQueryOption.ApplyTo(位于System.Web.Http.OData.query.ODataQueryOptions.ApplyTo的IQueryable查询、ODataQuerySettings查询设置、iAssemblisResolver汇编解析程序)\r\n(位于System.Web.Http.OData.query.ODataQueryOptions`1.ApplyTo的IQueryable查询、ODataQuerySettings查询设置)\r\n(位于System.Web.Http.OData.query.ODataQueryOptions`1.ApplyTo的IQueryable查询、ODataQuerySettings查询设置)\r\n在System.Web.Http.OData.Query.ODataQueryOptions.ApplyTo(IQueryable查询)\r\n在System.Web.Http.OData.Query.ODataQueryOptions`1.ApplyTo(IQueryable查询)\r\n在SchoolManagement.HTML5.Controllers.OrgController.getorganizer(ODataQueryOptions选项)在c:\\Projects\\AuthProj\\Controllers\\OrgController.cs:lambda\u方法的第160行\r\n(闭包,对象,对象[])\r\n位于System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.c\u DisplayClass10.b\u 9(对象实例,对象[]方法参数)\r\n位于System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecute(对象实例,对象[]参数)\r\n在System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext,IDictionary`2参数,CancellationToken CancellationToken)\r\n--从引发异常的上一个位置开始的堆栈结束跟踪---\r\n在System.Runtime.CompilerServices.TaskWaiter.ThrowForOnSuccess(任务任务)\r\n在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)\r\n在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n在System.Web.Http.Controllers.ApiControllerActionInvoker.d\u 0.MoveNext()\r\n---从引发异常的上一个位置开始的堆栈结束跟踪----\r\n在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务任务)\r\n在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务任务)\r\n在System.Runtime.CompilerServices.TaskAwaiter`1.GetRe