0

Error

    Severity    Code    Description Project File    Line    Suppression State
    Error   CS1501  No overload for method 'ProjectTo' takes 0 arguments

C#

       public static async Task<PagedResult<U>> GetPagedAsync<T, U>(this IQueryable<T> query, int page, int pageSize) where U : class
    {

        var result = new PagedResult<U>();
        result.CurrentPage = page;
        result.PageSize = pageSize;
        result.RowCount = await query.CountAsync();

        var pageCount = (double)result.RowCount / pageSize;
        result.PageCount = (int)Math.Ceiling(pageCount);

        var skip = (page - 1) * pageSize;
        result.Results = await query.Skip(skip)
                                     .Take(pageSize)
                                     .ProjectTo<U>()
                                     .ToListAsync();
        return result;
    }

I am getting above error after migration core 6.0 to core 7.0

strong text

7
  • have you installed AutoMapper package?
    – Vivek Nuna
    Commented Nov 28, 2022 at 8:46
  • Yes installed latest version Automapper 12.0.0
    – User
    Commented Nov 28, 2022 at 8:47
  • do you have any other assemblies that have an implementation from ProjectTo? Commented Nov 28, 2022 at 8:49
  • No, we didnot use
    – User
    Commented Nov 28, 2022 at 8:50
  • @User have you added using AutoMapper; on top of the class?
    – Vivek Nuna
    Commented Nov 28, 2022 at 8:52

1 Answer 1

2

ProjectTo methods provided by AutoMapper.QueryableExtensions require IConfigurationProvider. You can use one from IMapper or try resolving IConfigurationProvider directly:

IMapper mapper = ...; // resolve from the DI

var result = query
   .ProjectTo<SomeClass>(mapper.ConfigurationProvider)
   // ...
   ;

Or

IConfigurationProvider cfg = ...; // resolve from the DI

var result = query
   .ProjectTo<SomeClass>(cfg)
   // ...
   ;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.