У меня есть два класса, которые AccountSubscription и AccountSubscriptionDto .
Мне нужно сопоставить «AccountNumber» с «AccountList» как набор AccontNumbers (IList).
public class AccountSubscription : BaseEntity
{
[Required]
public int CustomerNumber { get; set; }
[Required]
public long AccountNumber { get; set; }
}
и
public class AccountSubscriptionDto : BaseDto
{
[Required]
public int CustomerNumber { get; set; }
[Required]
public IList<long> AccountList { get; set; }
}
Вот что я сделал для отображения AccountNumber в AccountList.
AutoMapperProfile.cs
CreateMap<IList<AccountSubscription>, IList<AccountSubscriptionDto>> ()
.ConstructUsing(list => list.GroupBy(g => new { g.CustomerNumber })
.Select(s => new AccountSubscriptionDto
{
CustomerNumber = s.Key.CustomerNumber,
AccountList = s.Select(t => t.AccountNumber).ToList()
}).ToList()
);
Когда я запускаю свое приложение и использую метод AccountSubscription Method, я получаю эту ошибку в результате:
"error": "Error mapping types.
Mapping types:
PagedList`1 -> IEnumerable`1
WestCore.Shared.Collections.Pagination.PagedList`1[[WestCore.Domain.Entities.PCsbins.AccountSubscription, WestCore.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] -> System.Collections.Generic.IEnumerable`1[[WestCore.AppCore.Models.PCsbins.Account.AccountSubscriptionDto, WestCore.AppCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]"
Редактировать : Вот как я могу вызвать mapper в моем приложении,
return DomainResult<IPagedList<AccountSubscriptionDto>>
.Success(_mapper.Map<IPagedList<AccountSubscriptionDto>>(await _repository.
GetPagedListAsync(pageIndex, pageSize, cancellationToken: ctx)));