2012-11-27 8 views
12

LỖIautomapper Thiếu cấu hình bản đồ loại hoặc bản đồ không được hỗ trợ.?

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 

Phương pháp hành động:

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

Khi tôi lấy khách hàng từ tổ chức nào, tôi nhận được lỗi trên. Tại sao tôi chỉ gặp lỗi này sau khi tìm nạp?

Trả lời

23

Dường như bạn muốn bỏ qua Thành phố, Ngành và PowerSuppliers từ bản đồ của bạn.

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

Tôi đã đưa ra giả định này vì bạn đang đặt chúng theo cách thủ công. Tất nhiên bạn có thể tạo ánh xạ cho chúng và tự động hóa chúng.

+0

Xin cảm ơn ... –