我正尝试使用 AutoMapper 将Func<IQueryable<T>, IOrderedQueryable<T>>
转换为Func<IQueryable<U>, IOrderedQueryable<U>>
,如下所示:
MapperConfiguration config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Func<IQueryable<T>, IOrderedQueryable<T>>, Func<IQueryable<U>, IOrderedQueryable<U>>>();
});
config.CreateMapper();
Mapper mapper = new Mapper(config);
var orderableOfU = mapper.Map<Func<IQueryable<U>, IOrderedQueryable<U>>>(orderableOfT);
但是它不起作用!我收到以下异常:
System.Func
2[System.Linq.IQueryable
1 [TanvirArjel.Application.DTOs.PostDetailsDto],System.Linq.IOrderedQueryable`1 [TanvirArjel.Application.DTOs.PostDetailsDto]]需要具有0 args或仅可选的构造函数args。 (参数“类型”)
这是我的通用类型:
public class Specification<T> where T : class
{
public List<Expression<Func<T, bool>>> Conditions { get; set; } = new List<Expression<Func<T, bool>>>();
public Func<IQueryable<T>, IIncludableQueryable<T, object>> Includes { get; set; }
public List<string> IncludeStrings { get; } = new List<string>();
public Func<IQueryable<T>, IOrderedQueryable<T>> OrderBy { get; set; }
public (string ColumnName, string SortDirection) OrderByDynamic { get; set; }
public Expression<Func<T, object>> GroupBy { get; set; }
public int? Skip { get; set; }
public int? Take { get; set; }
}
实际上,我正在尝试将Specification<Post>
映射到Specification<PostDetailsDto>
。
任何帮助将不胜感激!