如何解决C#OData:在ODataQueryOptions变量生成器中创建过滤器
我在存储库查询中有一个OData查询。
如果可能,需要在ODataQueryOptions中创建变量。过滤器要求以示例为例,说明=“国际”
http:// localhost / odata / GetAddressTypeDto()?$ filter = Descriptioneq'International'
代码:
public async Task<AddressTypeDto> GetAddressTypeDto(ODataQueryOptions<AddressTypeDto> odataQueryOptions)
{
var dto = (IQueryable<AddressTypeDto>)odataQueryOptions.ApplyTo(_addressRepository.GetAddressTypes)();
var dtoList = await dto.ToListAsync();
return dto;
}
_addressRepository.GetAddressTypes() = // IQueryable which brings out this result {
new AddressTypeDto {AddressTypeId = 1,Description = "International"},new AddressTypeDto {AddressTypeId = 2,Description = "PO Box"},new AddressTypeDto {AddressTypeId = 3,Description = "Business"}
}
我们现在正在尝试在不使用API的情况下,在变量odataQueryOptions中创建国际过滤器。
稍后尝试对单元进行单元测试
var actualResult = address.GetAddressTypeDto(odataQueryOptions)
Assert.Equals(actualResult.AddressTypeId,1);
Assert.Equals(actualResult.Description,"International");
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。