带有odata的automapper是否支持多个orderby /?$orderby=Field1,Field2
Does automapper with odata support multiple orderby /?$orderby=Field1,Field2
.net 核心 2.2,automapper 9.0.0,efcore 2.2.6,odata 7.2.3
为了在上下文中使用自动地图,我使用了 AutoMapper.AspNetCore.OData.EFCore" Version="1.0.0" 包
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、扩展到用户、select、...
对于 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 完全支持这个吗?还是我忽略了什么?
程序包中存在错误。找到了,修复它。我将创建一个 PR。发现了一些关于分页/计数的其他错误。
已报告,也会为此创建 PR。
现在还需要删除 EnableQuery。
.net 核心 2.2,automapper 9.0.0,efcore 2.2.6,odata 7.2.3 为了在上下文中使用自动地图,我使用了 AutoMapper.AspNetCore.OData.EFCore" Version="1.0.0" 包
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、扩展到用户、select、...
对于 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 完全支持这个吗?还是我忽略了什么?
程序包中存在错误。找到了,修复它。我将创建一个 PR。发现了一些关于分页/计数的其他错误。
已报告,也会为此创建 PR。 现在还需要删除 EnableQuery。