Reputation: 145
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
Reputation: 21477
notifications.Select(Mapper.Map<Notification,NotificationDto>);
is a short version of
notifications.Select(n => Mapper.Map<Notification,NotificationDto>(n));
Upvotes: 1