我试图在ASP.NET MVC应用程序中使用AutoMapper,但是当我查看详细信息时,AutoMapper基本上告诉我它无法映射任何属性,但无法让此AutoMapper停止使用AutoMapperConfigurationExceptions打我。即。找不到个人资料?!?
我已经根据AutoMapper网站上的文档完成了所有操作。
Global.asax:
protected void Application_Start()
{
// neither of those two ways works
Mapper.Initialize(cfg => cfg.AddProfiles(typeof(ImageEntity2GalleryModelMapping)));
Mapper.Initialize(cfg => cfg.AddProfiles(Assembly.GetExecutingAssembly()));
}
映射个人资料:
public class ImageEntity2GalleryModelMapping : Profile
{
// take note that this used to be an override of Configure() but the
// AutoMapper API has changed recently to favor Ctor now
public ImageEntity2GalleryModelMapping()
{
CreateMap<Image, GalleryModel>()
.ForMember(dest => dest.ImageId, opt => opt.MapFrom(src => src.ImageId))
// and so on
;
}
}
在控制器内部:
public ActionResult Index()
{
return View(Mapper.Map<GalleryModel>(_dbContext.Images.ToList()));
}
我想念什么吗?
答案 0 :(得分:0)
好吧,刚发现,我确实需要映射到一个集合类(我的印象是AutoMapper隐式地处理了这个问题)。
只需更改
javax.security.auth.login.LoginException: Unable to obtain password from user
at org.apache.hadoop.security.UserGroupInformation.loginUserFromKeytab(UserGroupInformation.java:935)
对此
return View(Mapper.Map<GalleryModel>(_dbContext.Images));
现在可以使用了;)