Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.8k views
in Technique[技术] by (71.8m points)

c# - automapper Missing type map configuration or unsupported mapping.?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...