Easiest way to convert Func<IQueryable<T>, IOrderedQueryable<T>> to Func<IQueryable<U>, IOrderedQueryable<U>>

谁都会走 提交于 2020-01-03 04:40:11

问题


I am trying to convert Func<IQueryable<T>, IOrderedQueryable<T>> to Func<IQueryable<U>, IOrderedQueryable<U>> using AutoMapper as follows:

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);

But it does not work! I am getting the following exception:

System.Func2[System.Linq.IQueryable1[TanvirArjel.Application.DTOs.PostDetailsDto],System.Linq.IOrderedQueryable`1[TanvirArjel.Application.DTOs.PostDetailsDto]] needs to have a constructor with 0 args or only optional args. (Parameter 'type')

Here is my Generic type:

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; }
}

Actually I am trying to map Specification<Post> to Specification<PostDetailsDto>. Any help will be highly appreciated!

来源:https://stackoverflow.com/questions/59492563/easiest-way-to-convert-funciqueryablet-iorderedqueryablet-to-funciquerya

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!