Код: Выделить всё
public class Customer
{
public int Id { get; set; }
public string FullName { get; set; }
public DateTime DateOfBirth { get; set; }
public ICollection CustomerRatings { get; set; }
}
public class CustomerRating
{
public DateTime CreatedAt { get; set; }
public RatingType RatingType { get; set; }
}
public class CustomerSummaryDto
{
public int Id { get; set; }
public string FullName { get; set; }
public DateTime DateOfBirth { get; set; }
public CustomerRatingDto LatestRating { get; set; }
}
public class CustomerRatingDto
{
public RatingType RatingType { get; set; }
}
public enum RatingType
{
Low,
Medium,
High
}
< /code>
Мой запрос выглядит следующим образом: < /p>
var queryProjection = dbContext.Customers.Select(c => new CustomerSummaryDto
{
Id = c.Id,
FullName = c.FullName,
DateOfBirth = c.DateOfBirth,
LatestRating = c.CustomerRatings
.OrderByDescending(r => r.CreatedAt)
.Select(r => new CustomerRatingDto { RatingType = r.RatingType })
.FirstOrDefault()
});
var finalQuery = (IQueryable)queryOptions.ApplyTo(queryProjection, new ODataQuerySettings());
var result = await finalQuery.ToListAsync();
< /code>
Я хочу позволить клиенту делать: < /p>
GET /odata/CustomerSummaryDtos?$orderby=LatestRating/RatingType desc
< /code>
Но я получаю следующую ошибку: < /p>
Произошла ошибка при обработке вашего запроса.
«Статус»: 500,
не может применять odataqueryoptions of myapp.customersummarydto (Параметр 'Query')
Как я могу включить $ orderby Подробнее здесь: https://stackoverflow.com/questions/797 ... jected-dto