i最近将ODATA从(v5.9.1)更新为最新的稳定版本(v6.0.0),而在前一个我用来配置这样的环境的版本中:
//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));
现在更新后,如何获得与以前相同的结果?我的路线都不
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.
有什么想法吗?预先感谢。
我遇到了同样的问题。system.web.odata中有一个内部类,称为unqualifiedcallandenumprefixfreeresolver。从理论上讲,这将处理EnumpRefixFree和不合格的Namecall,但由于这是内部的,所以我现在必须写自己的。
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上,但目前尚无团队的答案,直到我们获得标准的东西,这是一个替代方案。
。github链接
问候,mihai