我对Automapper感到悲伤。
我的地图是:
private void CreateEntityToDomainMaps()
{
//Mapper.CreateMap<Model.Customer,Data.Customer>();
Mapper.CreateMap<Data.Customer, Model.Customer>()
.ForMember(x => x.CompanyName, o => o.MapFrom(z => z.CompanyName));
}
我的映射器是:
public T Map<T>(Data.Customer type)
{
return AutoMapper.Mapper.Map<Data.Customer, T>(type);
}
我的模型类是:
public class Customer
{
public string CompanyName { get; set; }
}
我的实体类是旧的Northwind Customer表的EF实体。
例外是:
用户代码未处理AutoMapper.AutoMapperMappingException消息=尝试将NorthwindEFAccess.Customer映射到 Model.Customer.Exception类型 抛出'AutoMapper.AutoMapperMappingException'。来源= AutoMapper StackTrace:at AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext 在AutoMapper.MappingEngine.Map(对象源,类型 sourceType,Type destinationType)at AutoMapper.MappingEngine.Map [TSource,TDestination](TSource source)
在AutoMapper.Mapper.Map [TSource,TDestination](TSource源)
在Model.Mapper.CustomerMapper.Map [T](客户类型)中 d:\程序\ MVC \项目\ BestPracticeNWTelerikMVC \ Model.Mapper \ CustomerMapper.cs:行 10,在Services.CustomerService.GetAllCustomers()中 d:\程序\ MVC \项目\ BestPracticeNWTelerikMVC \ SERVICES \ CustomerService.cs:行 28在UITests.CustomerServiceTest.GetAllCustomersTest()中 d:\程序\ MVC \项目\ BestPracticeNWTelerikMVC \ UITests \ CustomerServiceTest.cs:行 81 InnerException:AutoMapper.AutoMapperMappingException
消息=尝试将NorthwindEFAccess.Customer映射到 Model.Customer.Missing类型映射配置或不支持 mapping.AutoMapper.AutoMapperMappingException类型的异常是 抛出。 Source = AutoMapper StackTrace:at AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context)InnerException:
我很困惑。