首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >内部实体中的AutoMapper异常

内部实体中的AutoMapper异常
EN

Stack Overflow用户
提问于 2022-05-20 13:03:36
回答 1查看 53关注 0票数 -1

我有实体和Dtos,如下所示

代码语言:javascript
运行
复制
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();
    }
}

当我通过品牌时,我在创造产品时出错。

代码语言:javascript
运行
复制
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 )
EN

回答 1

Stack Overflow用户

发布于 2022-05-20 14:00:57

您正在映射到ProjectEntity;但是ProjectEntity并没有使用您共享的这些类。也许你是想映射到ProductEntity

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72319389

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档