12

错误

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

当我从实体获取客户时,出现上述错误。为什么在获取后只有我得到这个错误?

4

1 回答 1

23

看起来您想从映射中忽略 Cities、Sectors 和 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());

我做了这个假设,因为您是手动设置它们。当然,您可以为这些创建映射并自动映射它们。

于 2012-11-27T16:04:53.233 回答