Я строю конечную точку ODATA, используя EF Core и OdataqueryOptions , и я хочу позволить клиентам $ orderby свойство, которое происходит из вложенной коллекции в моей проекции. DTOS: < /p>
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
на вложенное/комплексное свойство в DTO, спроектированном из EF -запроса с использованием Odata?
Я строю конечную точку ODATA, используя EF Core и OdataqueryOptions , и я хочу позволить клиентам $ orderby свойство, которое происходит из вложенной коллекции в моей проекции. DTOS: < /p> [code]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 [/code] на вложенное/комплексное свойство в DTO, спроектированном из EF -запроса с использованием Odata?