Automapper 'Project'메서드를 사용하여 EF 도메인 개체와 DTO 개체 간의 매핑을 수행하려고하지만 인터페이스에서 콘크리트 클래스로 프로젝트를 투영하려고 할 때 문제가 있습니다. . 내 EF 도메인 객체는 내 룩업 테이블에 일반적으로 사용하는 인터페이스 구현합니다Automapper 프로젝트 인터페이스에서 콘크리트 클래스
public interface ILookupItem
{
int Id { get; set; }
string Name { get; set; }
}
을 여기에 내 도메인 오브젝트의 예 :
내 응용 프로그램에서public partial class ReportType : ILookupItem
{
public int Id { get; set; }
public string Name { get; set; }
}
, 나는 DTO 객체를 사용하고 있습니다
,536 :public class LookupItemModel
{
public static void CreateMapping(IConfiguration configuration)
{
configuration.CreateMap<ILookupItem, LookupItemModel>();
}
public int Id { get; set; }
public string Name { get; set; }
}
나는 다음과 같은 호출 내 데이터베이스 쿼리를 수행하는 정확히 도메인 객체 인터페이스를 일치
return DbContext.Query<ReportType>().Project().To<LookupItemModel>();
그러나이 전화에 Automapper는 기능을 수행하기 위해 필요한 매핑 누락에 대한 오류를 제공합니다 :
Missing map from ReportType to LookupItemModel. Create using Mapper.CreateMap<ReportType, LookupItemModel>.
내가 매핑이 알 필요합니다 모든 이후 인터페이스에서 수행 할 수 있다고 가정했을
데이터를 가져 오는 속성입니다 (Id & 이름). 인터페이스의 각 구체적 구현을위한 맵을 만들지 않고도이 프로젝션을 수행 할 수있는 기능이 누락 되었습니까?
감사합니다.
LookupItemModel에서 CreateMapping()을 호출 한 적이 있습니까? –