使用带有 lambda 表达式的自动映射器

using auto mapper with lambda expression

我是 C# 的新手,我正在学习 C# 课程,其中我们使用一个名为 auto mapper 的包,它接受源和目标两个输入,代码是:

  var User_id = User.Identity.GetUserId();
            var notifications = _context.UserNotifications
                .Where(un => un.UserId == User_id)
                .Select(un => un.Notification)
                .Include(n => n.Gig.Artist)
                .ToList();
            Mapper.CreateMap<ApplicationUser, UserDto>();
            Mapper.CreateMap<Gig, GigDto>();
            Mapper.CreateMap<Notification, NotificationDto>(); 
            r   var User_id = User.Identity.GetUserId();
            var notifications = _context.UserNotifications
                .Where(un => un.UserId == User_id)
                .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>);

我的问题在最后一行,为什么我们没有像那样将通知对象传递给 Map 方法:

return notifications.Select(n =>
Mapper.Map<Notification,NotificationDto>(n));

notifications.Select(Mapper.Map<Notification,NotificationDto>);

的缩写

notifications.Select(n => Mapper.Map<Notification,NotificationDto>(n));

参见:https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/conversions#method-group-conversions