Подтвердить что ты не робот

Automapper Отсутствует конфигурация карты типа или неподдерживаемое отображение.?

ОШИБКА

Missing type map configuration or unsupported mapping.

Mapping types:
Cities_C391BA93C06F35100522AFBFA8F6BF3823972C9E97D5A49783829A4E90A03F00 -> IEnumerable`1
System.Data.Entity.DynamicProxies.Cities_C391BA93C06F35100522AFBFA8F6BF3823972C9E97D5A49783829A4E90A03F00 -> System.Collections.Generic.IEnumerable`1[[OsosPlus2.Core.DataAccess.Cities, OsosPlus2.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]

Destination path:
CustomerViewModel.Cities.Cities

Source value:
System.Data.Entity.DynamicProxies.Cities_C391BA93C06F35100522AFBFA8F6BF3823972C9E97D5A49783829A4E90A03F00

Метод действия:

public ActionResult _EditCustomer(int CustomerId)
{
    Customers customer = entity.Customers.FirstOrDefault(x => x.sno == CustomerId);
    CustomerViewModel customerViewModel = new CustomerViewModel();
    customerViewModel = AutoMapper.Mapper.Map<Customers, CustomerViewModel>(customer);

    customerViewModel.Sectors = entity.Sectors;
    customerViewModel.Cities = entity.Cities;
    customerViewModel.PowerSuppliers = entity.PowerSuppliers;

    return PartialView(customerViewModel);
}

Когда я вывожу клиента из объекта, я получаю выше ошибки. Почему только я получаю эту ошибку после извлечения?

4b9b3361

Ответ 1

Похоже, вы хотите игнорировать города, сектора и PowerSuppliers из вашего сопоставления.

Mapper.CreateMap<Customers, CustomerViewModel>()
                .ForMember(c => c.Sectors, option => option.Ignore())
                .ForMember(c => c.Cities , option => option.Ignore())
                .ForMember(c => c.PowerSuppliers , option => option.Ignore());

Я сделал это предположение, поскольку вы устанавливаете их вручную. Разумеется, вы можете создавать сопоставления для них и автоматизировать их также.