2016-12-06 5 views
3

ODataを(v5.9.1)から最新の安定版(v6.0.0)に更新しました。前者では、私はこのように自分の環境を設定しました:OData v6.0.0でEnableCaseInsensitive、EnableEnumPrefixFree、EnableUnqualifiedNameCallを有効にする方法

 //Allows calling the Url like {entityAction}/{id} 
     config.SetUrlConventions(ODataUrlConventions.KeyAsSegment); 

     //Allows urls to be case insensitive 
     config.EnableCaseInsensitive(true); 

     // Remove the necessity of having to specify the namespace of enums. 
     config.EnableEnumPrefixFree(true); 

     //This allows call a function without using the full namespace. 
     config.EnableUnqualifiedNameCall(true); 

     config.MapODataServiceRoute("odata", "api/rest", 
     edmModel, new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer)); 

更新後、以前と同じ結果をどのように達成できますか?例えば、私のルートのなし「localhostの/ ODATA /人/」、それは次のようなメッセージを示して作業している:

The path template 'people/{parentId}/emails' on the action 'Get' in controller 'PersonEmails' is not a valid OData path template. The operation import overloads matching 'people' are invalid. This is most likely an error in the IEdmModel. 

任意のアイデア?前もって感謝します。

答えて

5

同じ問題が発生しました。 System.Web.ODataにUnqualifiedCallAndEnumPrefixFreeResolverという内部クラスがあります。これは理論的にはEnumPrefixFreeとUnqualifiedNameCallの両方を扱いますが、これは内部的なものなので私自身は今のところ自分で書く必要がありました。

public class UnqualifiedCallAndEnumPrefixFreeResolver : ODataUriResolver 
{ 
    private readonly StringAsEnumResolver _stringAsEnum = new StringAsEnumResolver(); 
    private readonly UnqualifiedODataUriResolver _unqualified = new UnqualifiedODataUriResolver(); 

    private bool _enableCaseInsensitive; 

    public override bool EnableCaseInsensitive 
    { 
     get { return this._enableCaseInsensitive; } 
     set 
     { 
      this._enableCaseInsensitive = value; 
      _stringAsEnum.EnableCaseInsensitive = this._enableCaseInsensitive; 
      _unqualified.EnableCaseInsensitive = this._enableCaseInsensitive; 
     } 
    } 

    #region UnqualifiedODataUriResolver 

    public override IEnumerable<IEdmOperation> ResolveBoundOperations(IEdmModel model, string identifier, 
     IEdmType bindingType) 
    { 
     return _unqualified.ResolveBoundOperations(model, identifier, bindingType); 
    } 

    public override IEnumerable<IEdmOperation> ResolveUnboundOperations(IEdmModel model, string identifier) 
    { 
     return _unqualified.ResolveUnboundOperations(model, identifier); 
    } 

    #endregion 

    #region StringAsEnumResolver 

    public override void PromoteBinaryOperandTypes(BinaryOperatorKind binaryOperatorKind, 
     ref SingleValueNode leftNode, ref SingleValueNode rightNode, out IEdmTypeReference typeReference) 
    { 
     _stringAsEnum.PromoteBinaryOperandTypes(binaryOperatorKind, ref leftNode, ref rightNode, out typeReference); 
    } 

    public override IEnumerable<KeyValuePair<string, object>> ResolveKeys(IEdmEntityType type, 
     IDictionary<string, string> namedValues, Func<IEdmTypeReference, string, object> convertFunc) 
    { 
     return _stringAsEnum.ResolveKeys(type, namedValues, convertFunc); 
    } 

    public override IEnumerable<KeyValuePair<string, object>> ResolveKeys(IEdmEntityType type, 
     IList<string> positionalValues, Func<IEdmTypeReference, string, object> convertFunc) 
    { 
     return _stringAsEnum.ResolveKeys(type, positionalValues, convertFunc); 
    } 

    public override IDictionary<IEdmOperationParameter, SingleValueNode> ResolveOperationParameters(
     IEdmOperation operation, IDictionary<string, SingleValueNode> input) 
    { 
     return _stringAsEnum.ResolveOperationParameters(operation, input); 
    } 

    #endregion 
} 

次のように使用方法は次のようになります。

configuration.MapODataServiceRoute(
      "ODataRoute", 
      null, 
      builder => 
       builder.AddService(ServiceLifetime.Singleton, sp => BuildModel()) 
        .AddService<IEnumerable<IODataRoutingConvention>>(ServiceLifetime.Singleton, sp => 
          ODataRoutingConventions.CreateDefaultWithAttributeRouting("ODataRoute", configuration)) 
        .AddService<ODataUriResolver>(ServiceLifetime.Singleton, sp => new UnqualifiedCallAndEnumPrefixFreeResolver 
        { 
         EnableCaseInsensitive = true 
        }) 
     );   

は、私はまた、問題としてのGitHub上での投稿ですが、私たちは中に何かを得るまでのチームから今無応答のために、このworkarroundは、代替です標準。

Github link

よろしく、 ミハイ

+0

あなたの答えをありがとうございました!私はそれを試してみよう! – Bruno

+1

これはほぼ完璧です。 EnableCaseInsensitiveフラグがfalseにリセットされている現在のODataランタイムに「問題」があります。常にtrueを返すようにEnableCaseInsensitiveプロパティを変更し、回避策としてラップされたURIリゾルバEnableCaseInsensitiveを常にtrueに設定する必要があります。 - 私は原因とこれのためのより良い解決策を研究しており、すべてあなたに戻ってくるでしょう:) –

+0

ありがとう。最近ODataチームにはかなり不満がありました。最近のカップルバージョンは非常にバグがあり、ドキュメントは更新されず、バグレポートは無視されます。感心しない – Porco

関連する問題