Javascript 映射器不包含CreateMap C的定义# public IEnumerable GetNewNotifications() { var userId=User.Identity.GetUserId(); var notifications=\u context.UserNotifications .Where(un=>un.UserId==UserId) .Select(un=>un.Notification) .包括(n=>n.Gig.Artist) .ToList(); CreateMap(); CreateMap(); CreateMap(); 返回通知。选择(Mapper.Map); }
您能否帮助我正确定义此CreateMap,并解释以这种方式定义后显示此消息的原因?为什么找不到这个方法?正如Ben所指出的,在版本5中不推荐使用静态映射器创建映射。在任何情况下,您展示的代码示例都会有糟糕的性能,因为您会在每次请求时重新配置映射 相反,将映射配置放入Javascript 映射器不包含CreateMap C的定义# public IEnumerable GetNewNotifications() { var userId=User.Identity.GetUserId(); var notifications=\u context.UserNotifications .Where(un=>un.UserId==UserId) .Select(un=>un.Notification) .包括(n=>n.Gig.Artist) .ToList(); CreateMap(); CreateMap(); CreateMap(); 返回通知。选择(Mapper.Map); },javascript,c#,linq,mapper,automapper-3,Javascript,C#,Linq,Mapper,Automapper 3,您能否帮助我正确定义此CreateMap,并解释以这种方式定义后显示此消息的原因?为什么找不到这个方法?正如Ben所指出的,在版本5中不推荐使用静态映射器创建映射。在任何情况下,您展示的代码示例都会有糟糕的性能,因为您会在每次请求时重新配置映射 相反,将映射配置放入AutoMapper.Profile中,并在应用程序启动时仅初始化映射器一次 public IEnumerable<NotificationDto> GetNewNotifications() { var user
AutoMapper.Profile
中,并在应用程序启动时仅初始化映射器一次
public IEnumerable<NotificationDto> GetNewNotifications()
{
var userId = User.Identity.GetUserId();
var notifications = _context.UserNotifications
.Where(un => un.UserId == userId)
.Select(un => un.Notification)
.Include(n => n.Gig.Artist)
.ToList();
Mapper.CreateMap<ApplicationUser, UserDto>();
Mapper.CreateMap<Gig, GigDto>();
Mapper.CreateMap<Notification, NotificationDto>();
return notifications.Select(Mapper.Map<Notification, NotificationDto>);
}
使用AutoMapper;
//通过将配置放入概要文件来重用配置
公共类MyMappingProfile:Profile{
公共MyMappingProfile(){
CreateMap正如Ben所指出的,在版本5中不推荐使用静态映射器创建映射。在任何情况下,您显示的代码示例都会有很差的性能,因为您会在每次请求时重新配置映射
相反,将映射配置放入AutoMapper.Profile
中,并在应用程序启动时仅初始化映射器一次
public IEnumerable<NotificationDto> GetNewNotifications()
{
var userId = User.Identity.GetUserId();
var notifications = _context.UserNotifications
.Where(un => un.UserId == userId)
.Select(un => un.Notification)
.Include(n => n.Gig.Artist)
.ToList();
Mapper.CreateMap<ApplicationUser, UserDto>();
Mapper.CreateMap<Gig, GigDto>();
Mapper.CreateMap<Notification, NotificationDto>();
return notifications.Select(Mapper.Map<Notification, NotificationDto>);
}
使用AutoMapper;
//通过将配置放入概要文件来重用配置
公共类MyMappingProfile:Profile{
公共MyMappingProfile(){
CreateMap请查看AutoMaper的升级详细信息请查看AutoMaper的升级详细信息啊抱歉,它应该是CreateMap();
而不是配置文件中的Mapper.CreateMap();
。我编辑了答案啊抱歉,它应该是CreateMap();
而不是Mapper.CreateMap())在个人资料中。我编辑了答案