带odata的自动映射器是否支持多个orderby /?$ orderby = Field1,Field2

问题描述 投票:0回答:1

。net core 2.2,automapper 9.0.0,efcore 2.2.6,odata 7.2.3为了在上下文上使用自动映射,我使用了AutoMapper.AspNetCore.OData.EFCore“ Version =” 1.0.0“ package

public class RolesController : ODataController
{
    private readonly ApplicationDbContext _context;
    private readonly IMapper _mapper;

    public RolesController(ApplicationDbContext context, IMapper mapper)
    {
        _context = context ?? throw new ArgumentNullException(nameof(context));
        _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
    }

    [EnableQuery]
    public async Task<IActionResult> Get(ODataQueryOptions<RoleGridRow> options)
    {
        return Ok(await _context.Roles.AsNoTracking().GetQueryAsync(_mapper, options));
    }
}


public RolesProfile()
    {
        CreateMap<ApplicationRole, RoleGridRow>()
            .ForMember(dest => dest.Users, opt => opt.MapFrom(src => src.UserRoles ));
        CreateMap<ApplicationUserRole, User>()
            .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.UserId))
            .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.User.Name));
    }

ApplicationRole / User / UserRole继承自IdentityRole / User / UserRole所有导航设置正确。

我需要以下DTO

 public class RoleGridRow
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public bool IsActive { get; set; }
    public List<User> Users { get; set; }
}

使用OData,所有调用似乎都可以正常工作:orderby,展开为用户,选择,...

对于orderby,当我尝试按多个字段进行排序时,例如:“ https://localhost:5001/odata/roles?$ orderby = IsActive,Name”,出现以下异常:

No generic method 'ThenBy' on type 'System.Linq.Queryable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.

automapper完全支持吗?还是我忽略的东西?

odata automapper ef-core-2.2
1个回答
0
投票

包装中存在错误。找到它,修复它。我将创建一个PR。发现了有关分页/计数的其他一些错误。

已报告,还将为此创建PR。现在也需要删除EnableQuery。

© www.soinside.com 2019 - 2024. All rights reserved.