0
votes

.net core 2.2, automapper 9.0.0, efcore 2.2.6, odata 7.2.3 In order to use auto map on the context I am using the 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 are inherited from IdentityRole/User/UserRole All navigations setup correctly.

I need the following 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; }
}

With OData all calls seem to be working: orderby, expand into users, select, ...

For orderby, the moment I try to order by multiple fields like: "https://localhost:5001/odata/roles?$orderby=IsActive,Name", I get the following exception:

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.

Does automapper support this at all? or is it something I am overlooking?

1

1 Answers

1
votes

There was a bug in the package. Found it, fixing it. I will create a PR. Found a few other bugs regarding paging / count.

Reported, will create PR for that as well. EnableQuery needs to be removed as well for now.