我有实体和Dtos,如下所示
public abstract class ProductEntity : BaseEntity {
public string? Title { get; set; }
public string? Subtitle { get; set; }
public IEnumerable<BrandEntity>? Brands { get; set; }
}
public class ProductReadDto {
public string? Title { get; set; }
public string? Subtitle { get; set; }
public IEnumerable<IdTitleReadDto>? Brands { get; set; }
}
public class ProductCreateUpdateDto {
public string? Title { get; set; }
public string? Subtitle { get; set; }
public IEnumerable<Guid>? Brands { get; set; }
}
public class BrandEntity : BaseEntity {
public string Title { get; set; }
public string? Subtitle { get; set; }
public IEnumerable<ProductEntity>? Product { get; set; }
}
public class BrandReadDto {
public string? Title { get; set; }
public string? Subtitle { get; set; }
}
public class BrandCreateUpdateDto {
public string? Title { get; set; }
public string? Subtitle { get; set; }
}
public class AutoMapperProfile : Profile {
public AutoMapperProfile() {
CreateMap<BrandEntity, IdTitleReadDto>().ReverseMap();
CreateMap<BrandEntity, IdTitleCreateUpdateDto>().ReverseMap();
CreateMap<ProductEntity, ProductReadDto>().ReverseMap();
CreateMap<ProductEntity, ProductCreateUpdateDto>().ReverseMap();
}
}
当我通过品牌时,我在创造产品时出错。
AutoMapper.AutoMapperMappingException: Error mapping types.
Mapping types:
ProductCreateUpdateDto -> ProductEntity
Utilities_aspnet.Product.ProductCreateUpdateDto -> Utilities_aspnet.Product.ProductEntity
Type Map configuration:
ProductCreateUpdateDto -> ProductEntity
Utilities_aspnet.Product.ProductCreateUpdateDto -> Utilities_aspnet.Product.ProductEntity
Destination Member:
Reference
---> AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.
Mapping types:
Guid -> ReferenceEntity
System.Guid -> Utilities_aspnet.IdTitle.ReferenceEntity
at lambda_method1810(Closure , Guid , ReferenceEntity , ResolutionContext )
at lambda_method1809(Closure , Object , ProductEntity , ResolutionContext )
--- End of inner exception stack trace ---
at lambda_method1809(Closure , Object , ProductEntity , ResolutionContext )
发布于 2022-05-20 14:00:57
您正在映射到ProjectEntity
;但是ProjectEntity
并没有使用您共享的这些类。也许你是想映射到ProductEntity
https://stackoverflow.com/questions/72319389
复制相似问题