2016-12-05 6 views
1

$orderbyは、派生型のプロパティに失敗し

アセンブリがMicrosoft.OData.Core 6.15.0.0

System.Web.OData 5.9.1.0 に影響を与えました

再現は

*モデルのステップ:

public abstract class Person 
    { 
     public int Id { get; set; } 
     public string Name { get; set; } 
    } 
    public class Manager : Person 
    { 
     public string ManagerProperty { get; set; } 
    } 
    public class Supervisor : Person 
    { 
     public string SupervisorProperty { get; set; } 
    } 

私はエラーに

クエリを取得派生メンバープロパティに注文することになりまし問い合わせる場合:

http://someserver/odata/persons?$isof=('Namespace.Manager')&$orderby=Namespace.Manager/ManagerProperty 

エラーの詳細:

"message":"The method or operation is not implemented.","type":"System.NotImplementedException","stacktrace":" at Microsoft.OData.Core.UriParser.Visitors.QueryNodeVisitor`1.Visit(SingleEntityCastNode nodeIn)\r\n at System.Web.OData.Query.Validators.OrderByQueryValidator.OrderByModelLimitationsValidator.TryValidate(OrderByClause orderByClause, Boolean explicitPropertiesDefined)\r\n at System.Web.OData.Query.Validators.OrderByQueryValidator.Validate(OrderByQueryOption orderByOption, ODataValidationSettings validationSettings)\r\n at System.Web.OData.Query.OrderByQueryOption.Validate(ODataValidationSettings validationSettings)\r\n at System.Web.OData.Query.Validators.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)\r\n at System.Web.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings)\r\n at System.Web.OData.EnableQueryAttribute.ValidateQuery(HttpRequestMessage request, ODataQueryOptions queryOptions)\r\n at System.Web.OData.EnableQueryAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor)\r\n at System.Web.OData.EnableQueryAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)" 
• 

期待される結果

をそれは注文する必要があります指定したプロパティによる結果

実績その結果、私はその後、問題を修正しましたが、私はそれが故に正解だ場合、誰かが

public override SingleValueNode Visit(SingleValuePropertyAccessNode nodeIn) 
      { 
       if (EdmLibHelpers.IsNotSortable(nodeIn.Property, _model)) 
       { 
        return nodeIn; 
       } 
       if (nodeIn.Source != null) 
       { 
        if(((SingleEntityCastNode)nodeIn.Source).EntityTypeReference != ((SingleEntityCastNode)nodeIn.Source).Source.EntityTypeReference) 
        { 
         return ((SingleEntityCastNode)nodeIn.Source).Source.Accept(this); 
        } 
        return nodeIn.Source.Accept(this); 
       } 
       return null; 
      } 
を助言してくださいすることができます確信している条件以下の追加 OrderByQueryValidator

public override SingleValueNode Visit(SingleValuePropertyAccessNode nodeIn) 
      { 
       if (EdmLibHelpers.IsNotSortable(nodeIn.Property, _model)) 
       { 
        return nodeIn; 
       } 
       if (nodeIn.Source != null) 
       { 
        return nodeIn.Source.Accept(this); 
       } 
       return null; 
      } 

方法は次の

*"message":"The method or operation is not implemented.","type":"System.NotImplementedException","stacktrace":" at Microsoft.OData.Core.UriParser.Visitors.QueryNodeVisitor`1.Visit(SingleEntityCastNode nodeIn)\r\n at System.Web.OData.Query.Validators.OrderByQueryValidator.OrderByModelLimitationsValidator.TryValidate(OrderByClause orderByClause, Boolean explicitPropertiesDefined)\r\n at System.Web.OData.Query.Validators.OrderByQueryValidator.Validate(OrderByQueryOption orderByOption, ODataValidationSettings validationSettings)\r\n at System.Web.OData.Query.OrderByQueryOption.Validate(ODataValidationSettings validationSettings)\r\n at System.Web.OData.Query.Validators.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)\r\n at System.Web.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings)\r\n at System.Web.OData.EnableQueryAttribute.ValidateQuery(HttpRequestMessage request, ODataQueryOptions queryOptions)\r\n at System.Web.OData.EnableQueryAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor)\r\n at System.Web.OData.EnableQueryAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)" 
* 

ブレーク

答えて

0

これは、他のノードタイプのエラーを避けるために、SingleEntityCastNodeパラメータのVisitメソッドを直接オーバーライドする方が良いです。

 public override SingleValueNode Visit(SingleValuePropertyAccessNode nodeIn) 
     { 
      if (EdmLibHelpers_IsNotSortable(nodeIn.Property, _model)) 
      { 
       return nodeIn; 
      } 
      if (nodeIn.Source != null) 
      {    
       return nodeIn.Source.Accept(this); 
      } 
      return null; 
     } 

     public override SingleValueNode Visit(SingleEntityCastNode nodeIn) 
     { 
      if (nodeIn.EntityTypeReference != nodeIn.Source.EntityTypeReference) 
      { 
       return nodeIn.Source.Accept(this); 
      } 
      return base.Visit(nodeIn); 
     } 
関連する問題