Код: Выделить всё
[EnableQuery]
public async Task Get([FromQuery] int? managerLevel,
[FromQuery] string? managerEmployeeNumber,
[FromQuery] bool isSearch = false,
ODataQueryOptions? options = null)
{
var userId = "[email protected]";
isSearch = true;
var employees = await mediator.Send(new ListEmployeesQuery(managerLevel, managerEmployeeNumber, userId, isSearch: isSearch), CancellationToken.None);
var filteredResults = options?.Filter.ApplyTo(employees.AsQueryable(), new ODataQuerySettings()) as IQueryable;
var expandedResults = options?.SelectExpand.ApplyTo(filteredResults, new ODataQuerySettings()) as IQueryable;
return Ok(employees);
}
Код: Выделить всё
https://localhost:7145/odata/ExportSearchResults/
?$filter=((contains(forename, 'dange')) or (contains(surname, 'dange')) or (contains(employeeNumber, 'dange'))) and (status eq true)
&$expand=PerformanceReviews,EngagementScores,TalentAssessments,SecuredEmployeeDetails
&isSearch=true&$top=5&$skip=0&$count=true
Кроме того, filteredResults возвращает правильные результаты с применением $filter. expandResults возвращает значение null.
Вот свойство SelectExpand:

А вот моя конфигурация OData:
Код: Выделить всё
public static ODataConventionModelBuilder AddODataEntities(this ODataConventionModelBuilder modelBuilder)
{
modelBuilder.EntitySet("Employee").EntityType.HasKey(entity => entity.EmployeeId);
modelBuilder.EntitySet("PerformanceReview").EntityType.HasKey(entity => entity.Id);
modelBuilder.EntitySet("EngagementScores").EntityType.HasKey(entity => entity.Id);
modelBuilder.EntitySet("TalentAssessments").EntityType.HasKey(entity => new { entity.EmployeeId, entity.Year });
modelBuilder.EntitySet("TalentAssessmentAuditLogs").EntityType.HasKey(entity => new { entity.EmployeeId, entity.Year, entity.IdentityId, entity.EffectiveDate });
modelBuilder.EntitySet("EmployeeDetails").EntityType.HasKey(entity => new { entity.EmployeeId });
modelBuilder.EntitySet("MobilityConsiderations").EntityType.HasKey(entity => entity.Id);
modelBuilder.EntitySet("ExportSearchResults").EntityType.HasKey(entity => entity.EmployeeId);
return modelBuilder;
}
Код: Выделить всё
services.AddControllers().AddOData(opt => opt.Count().Filter().Expand().Select().OrderBy().SetMaxTop(100)
.AddRouteComponents("odata", builder.GetEdmModel()));
Заранее спасибо.
Я пытаюсь использовать то же самое фильтр, примененный во внешнем интерфейсе для экспорта того же результата в файл Excel, поэтому мне нужно, чтобы $expand и $filter работали правильно. В этом случае $expand не работает внутри контроллера. Только после возврата результата.
Подробнее здесь: https://stackoverflow.com/questions/788 ... he-backend