automapper缺少类型映射配置或不支持的映射。? [英] automapper Missing type map configuration or unsupported mapping.?
本文介绍了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);
}
当我获取客户的实体,我得到上述错误。为什么只有我取后得到这个错误?
When I fetch customer from entity, I get above error. Why only I get this error after fetching?
推荐答案
看起来你要忽略的城市,部门和PowerSuppliers从你的映射。
It looks like you want to ignore Cities, Sectors and PowerSuppliers from your mapping.
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());
我做这样的假设,因为你是手动设置。当然,你可以创建映射这些和自动映射它们。
I made this assumption since you are setting them manually. Of course you could create mappings for these and automap them as well.
这篇关于automapper缺少类型映射配置或不支持的映射。?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文