我正在尝试按照我的主要实体Address
上的复杂类型Customer
对数据进行排序。
public partial class Customer
{
public Customer()
{
this.Address = new Address();
}
public string Name { get; set; }
public Address Address { get; set; }
}
public partial class Address
{
public string Address1 { get; set; }
public string Address2 { get; set; }
public string Town { get; set; }
public string County { get; set; }
public string PostCode { get; set; }
}
我查询了数据,我可以使用$sort=Name
按名称对其进行排序,但是当我$sort=Address.PostCode
时,我得到了:
"The child type 'Address.PostCode' in a cast was not an entity type. Casts can only be performed on entity types.","type":"Microsoft.Data.OData.ODataException","stacktrace":" at Microsoft.Data.OData.Query.DottedIdentifierBinder.BindDottedIdentifier(DottedIdentifierToken dottedIdentifierToken, BindingState state)\r\n at Microsoft.Data.OData.Query.MetadataBinder.BindCast(DottedIdentifierToken dottedIdentifierToken)\r\n at Microsoft.Data.OData.Query.MetadataBinder.Bind(QueryToken token)\r\n at Microsoft.Data.OData.Query.OrderByBinder.ProcessSingleOrderBy(BindingState state, OrderByClause thenBy, OrderByToken orderByToken)\r\n at Microsoft.Data.OData.Query.OrderByBinder.BindOrderBy(BindingState state, IEnumerable1 orderByTokens)\r\n at Microsoft.Data.OData.Query.ODataUriParser.ParseOrderByImplementation(String orderBy, IEdmType elementType, IEdmEntitySet entitySet)\r\n at System.Web.Http.OData.Query.OrderByQueryOption.get_OrderByClause()\r\n at System.Web.Http.OData.Query.OrderByQueryOption.get_OrderByNodes()\r\n at System.Web.Http.OData.Query.ODataQueryOptions.EnsureStableSortOrderBy(OrderByQueryOption orderBy, ODataQueryContext context)\r\n at System.Web.Http.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings)\r\n at System.Web.Http.QueryableAttribute.ApplyQuery(IQueryable queryable, ODataQueryOptions queryOptions)\r\n at System.Web.Http.QueryableAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor)\r\n at System.Web.Http.QueryableAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)"
当我$sort=Address/PostCode
时,我得到:
"Only ordering by properties at the root level is supported for non-primitive collections. Nested properties and expressions are not supported.","type":"Microsoft.Data.OData.ODataException","stacktrace":" at System.Web.Http.OData.Query.OrderByNode.CreateCollection(OrderByClause orderByClause)\r\n at System.Web.Http.OData.Query.OrderByQueryOption.get_OrderByNodes()\r\n at System.Web.Http.OData.Query.ODataQueryOptions.EnsureStableSortOrderBy(OrderByQueryOption orderBy, ODataQueryContext context)\r\n at System.Web.Http.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings)\r\n at System.Web.Http.QueryableAttribute.ApplyQuery(IQueryable queryable, ODataQueryOptions queryOptions)\r\n at System.Web.Http.QueryableAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor)\r\n at System.Web.Http.QueryableAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)"
那么我该如何排序?
我正在使用Entity Framework v6和System.Web.Http.OData v5。
由于