Automapper v4.0 был очень прямо вперед, чтобы использовать в методе, может кто-то помочь переписать для v5.0, пожалуйста (в частности, код Mapper):Перепишите код Automapper v5.0 до v4.0
public IEnumerable<NotificationDto> GetNewNotifications()
{
var userId = User.Identity.GetUserId();
var notifications = _context.UserNotifications
.Where(un => un.UserId == userId && !un.IsRead)
.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>);
}
UPDATE: кажется, что EF ядро не проецировать, что AutoMapper является отображение с:
return notifications.Select(Mapper.Map<Notification, NotificationDto>);
Но я получаю результаты в Почтальон со следующим кодом:
return notifications.Select(n => new NotificationDto()
{
DateTime = n.DateTime,
Gig = new GigDto()
{
Artist = new UserDto()
{
Id = n.Gig.Artist.Id,
Name = n.Gig.Artist.Name
},
DateTime = n.Gig.DateTime,
Id = n.Gig.Id,
IsCancelled = n.Gig.IsCancelled,
Venue = n.Gig.Venue
},
OriginalVenue = n.OriginalVenue,
OriginalDateTime = n.OriginalDateTime,
Type = n.Type
});
Линия mapper.map, похоже, не работает. Похоже, это нужно переписать тоже – Reza
Есть ли у вас какие-либо ошибки? отлично работает для меня –
Intellisense жалуется на уведомления о возврате этой строки. Выберите (Mapper.Map); –
Reza