C# automapper 缺少类型映射配置或不受支持的映射。?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13587824/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
automapper Missing type map configuration or unsupported mapping.?
提问by AliR?za Ad?yah?i
ERROR
错误
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
Action Method:
动作方法:
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?
当我从实体获取客户时,出现上述错误。为什么只有我在获取后才会收到此错误?
采纳答案by dove
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.
我做出这个假设是因为您是手动设置它们。当然,您可以为这些创建映射并自动映射它们。

