我正在创建一个实现OData 4的新Web API。我希望能够选择/扩展导航属性,但是我收到一个我不知道如何解决的错误。
我已经发布了请求uri,响应错误,示例代码和下面的堆栈跟踪。如果你看一下代码,“Phones”显然是一种方法,而不是像Id和Name这样的属性,但我认为我应该能够选择和扩展该方法的结果,就像属性一样。
如何允许API用户选择从该方法返回的值?
P.S。导航属性可能不是正确的名称(?)
请求URI
http://localhost:10013/Call?$select=*&$expand=Phones
RESPONSE
{
"error" : {
"code" : "",
"message" : "The query specified in the URI is not valid. Could not find a property named 'Phones' on type 'Call'.",
"innererror" : {
"message" : "Could not find a property named 'Phones' on type 'Call'.",
"type" : "Microsoft.OData.ODataException"
}
}
}
代码
public class CallController : ODataController
{
[EnableQuery]
public IQueryable<Call> GetCall(ODataQueryOptions options)
{
return DatabaseContext.Call.GetAll();
}
}
public class Call
{
public int Id { get; set; }
public string Name { get; set; }
public IEnumerable<Phone> Phones()
{
//just an example
var list = new List<Phone>();
return list as IEnumerable<Phone>
}
}
public class Phone
{
public int Id { get; set; }
public string Name { get; set; }
}
STACK TRACE
- Microsoft.OData.UriParser.SelectExpandBinder.GenerateExpandItem(ExpandTermToken tokenIn)
- System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
- System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
- System.Collections.Generic.List
1.InsertRange(Int32 index, IEnumerable
1个集合)
- Microsoft.OData.UriParser.SelectExpandBinder.Bind(ExpandToken tokenIn)
- Microsoft.OData.UriParser.SelectExpandSemanticBinder.Bind(ODataPathInfo odataPathInfo,ExpandToken expandToken,SelectToken selectToken,ODataUriParserConfiguration配置)
- Microsoft.OData.UriParser.ODataQueryOptionParser.ParseSelectAndExpandImplementation(String select,String expand,ODataUriParserConfiguration configuration,ODataPathInfo odataPathInfo)
Microsoft.OData.UriParser.ODataQueryOptionParser.ParseSelectAndExpand()
- System.Web.OData.Query.Validators.SelectExpandQueryValidator.Validate(SelectExpandQueryOption selectExpandQueryOption,ODataValidationSettings validationSettings)
- System.Web.OData.Query.SelectExpandQueryOption.Validate(ODataValidationSettings validationSettings)
- System.Web.OData.Query.Validators.ODataQueryValidator.Validate(ODataQueryOptions选项,ODataValidationSettings validationSettings)
- System.Web.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings)
- System.Web.OData.EnableQueryAttribute.ValidateQuery(HttpRequestMessage request,ODataQueryOptions queryOptions)
- System.Web.OData.EnableQueryAttribute.ExecuteQuery(Object response,HttpRequestMessage request,HttpActionDescriptor actionDescriptor,ODataQueryContext queryContext)
- System.Web.OData.EnableQueryAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
醇>