1

I am using the following:

  • EntityFrameworkCore 3.1.2
  • .Net Standard Library 2.1
  • Automapper 9.0.0
  • Automapper.Extension.Microsoft.DependencyInjection 7.0.0

My DI for AutoMapper looks like this:

services.AddAutoMapper(Assembly.GetExecutingAssembly());

I have an IMapFrom with default implementation:

using AutoMapper;

namespace Application.Common.Mappings
{
    public interface IMapFrom<T>
    {
        void Mapping(Profile profile) => profile.CreateMap(typeof(T), GetType());
    }
}

I have a DTO class as follows:

    public class ServiceRegistrationDto : IMapFrom<ServiceRegistration>
    {
        public string ServiceName { get; set; }

        public string MessageType { get; set; }

        public string ServiceURL { get; set; }

        public void Mapping(Profile profile)
        {
            profile.CreateMap<ServiceRegistration, ServiceRegistrationDto>();
        }
    }

In my Handler I am doing the following:

public async Task<ServiceRegistrationViewModel> Handle(GetServiceRegistrationListQuery request, CancellationToken cancellationToken)
{
    var serviceRegistrations = await _context.ServiceRegistrations
        .Where(s => s.MessageType.Equals(request.MessageType, StringComparison.InvariantCultureIgnoreCase))
        .ProjectTo<ServiceRegistrationDto>(_mapper.ConfigurationProvider)
        .ToListAsync(cancellationToken);

    return null;
}

The issue is that the "ProjectTo" is not a definition of IQueryable. I was under the impression that Automapper had Queryable Extensions. Am I missing a NuGet Package? I am following examples from Northwind Traders and I can't figure out what I have different.

I can get to "ProjectTo" using IMapper like this:

var x = _mapper.ProjectTo<ServiceRegistrationDto>(serviceRegistrations);

But I would prefer to do it as part of the IQueryable like you should be able to.

1 Answers1

0

I took a step back from the code and realized I was missing the

using AutoMapper.QueryableExtensions;

DOH!!!