ibrahim
ibrahim

Reputation: 145

using auto mapper with lambda expression

I am new to C# and I'm following a course in C# where we are using a package named auto mapper which takes two inputs the source and the target and the code is :

  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>);

my question is in the last line why we have not passed the notification object to the Map Method like that :

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

Upvotes: 0

Views: 858

Answers (1)

Robert McKee
Robert McKee

Reputation: 21477

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

is a short version of

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

see: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/conversions#method-group-conversions

Upvotes: 1

Related Questions