작동하지 않습니다와 나는 엔티티 있습니다Automapper 5.2 상속
public abstract class BaseEntity
{
public Int16 Id { get; set; }
public DateTime Timestamp { get; set; }
}
public class Certificate : BaseEntity
{
public String Name { get; set; }
public String Authority { get; set; }
public DateTime RecieveDate { get; set; }
public String Image { get; set; }
}
그리고 나는 뷰 모델이 BaseEntity를 실제로 매핑해야합니다. 제거하고 싶습니다.) ConfigureServices에 등록
public class MappingProfile : Profile
{
public MappingProfile()
{
CreateMap<Storage.Entities.Entities.BaseEntity, ViewModels.ViewModels.BaseViewModel>()
.Include<Storage.Entities.Entities.Certificate, ViewModels.ViewModels.Certificate>();
CreateMap<Storage.Entities.Entities.Certificate, ViewModels.ViewModels.Certificate>();
}
}
: (이것은 어떤 sence 만드는 경우) 상술 한
services.AddAutoMapper();
모든 3 개 클래스가 다른 프로젝트에 I는 매퍼 프로파일을 갖는다.
이 컨트롤러 생성자 :
private readonly Storage.Abstractions.Core.IStorage _storage;
private readonly IMapper _mapper;
public CertificateController(Storage.Abstractions.Core.IStorage storage, IMapper mapper)
{
this._storage = storage;
this._mapper = mapper;
}
내가 뷰 모델에 법인을지도 곳 방법을 얻을 :
IEnumerable<Storage.Entities.Entities.Certificate> certificates = await this._storage.GetRepository<ICertificateRepository>().AllAsync();
IEnumerable<ViewModels.ViewModels.Certificate>result = _mapper.Map<IEnumerable<Storage.Entities.Entities.Certificate>, IEnumerable<ViewModels.ViewModels.Certificate>>(certificates);
이 올바른지 같은데, 맞죠? 하지만 :
오류 매핑 유형.
매핑 유형 : 는 IEnumerable 1 -> IEnumerable
1 System.Collections.Generic.IEnumerable 1[[AlexanderTsema.Storage.Entities.Entities.Certificate, AlexanderTsema.Storage.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] -> System.Collections.Generic.IEnumerable
1 [AlexanderTsema.ViewModels.ViewModels.Certificate, AlexanderTsema.ViewModels 버전 1.0.0.0 = 문화 = 중립 PublicKeyToken = NULL]
및 내부 검색 : 누락 유형 맵 구성 또는 지원되지 않는 매핑.
매핑 유형 : 인증서 -> 인증서 AlexanderTsema.Storage.Entities.Entities.Certificate -> AlexanderTsema.ViewModels.ViewModels.Certificate
제발 조언.
Entity.Certificate를 Entity.Certificate에 매핑하려고했는데 제대로 작동합니다.
지저귐을 게시하기 전에 도움말 센터 기사를 읽으십시오. http://stackoverflow.com/help/tagging 특히 ** 제목에 태그를 사용해야합니까? ** 섹션 : _ 다음 형식 중 하나로 제목에 태그를 삽입하지 마십시오. [tag] : [question title] _ – Tseng
@ user2970104 빠른 질문이지만. IntelliSense에서 모든 인수를 제거하면 'AddAutoMapper'의 어떤 서명이 표시됩니까? 어떤 플랫폼을 사용합니까, 전체 .NET Framework입니까, 아니면 .NET Core 응용 프로그램입니까? 매개 변수없이 호출하면 왜 작동하지 않는지 이해하려고합니다. –
질문 제목 편집 : ASP.NET Core 1.1 Intellisense는 특정 내용을 표시하지 않습니다. @ MickaëlDerriey – user2970104