问题
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.Func
2[System.Linq.IQueryable
1[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