Base solution for your next web application
Open Closed

CreateMultiLingualMap #5208


User avatar
0
ymboda created

Hello !

Maybe there is something i misunderstood, but I can't automap my input dto with a multilingual entity. I'm using ASP NET Zero 5.4.1 startup template with ABP 3.2.0 update & .NET Core 2.1.

At the line :

var documentCategory = ObjectMapper.Map<DocumentCategory>(input);

of the method

private async Task Create(CreateOrEditDocumentCategoryDto input)

I get this exception :

_Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type For no matching constructor, add a no-arg ctor, add optional arguments, or map all of the constructor parameters

CreateOrEditDocumentCategoryDto -> DocumentCategory (Destination member list) Colnec.Documents.Dtos.CreateOrEditDocumentCategoryDto -> Colnec.Documents.DocumentCategory (Destination member list)

Unmapped properties: Translations_

What I'm trying is to convert the name from the dto (simple string) into the entity translations collection (with the default language). The exception seems normal because the map is configure with the dto as the destination, but before creating my own CreateMultiLingualMap function for handle the automatic mapping in this way, is there something I'm missing there ? I followed the documentation from ABP website.

Thank's a lot :)

[Table("DocumentCategories")]
    public class DocumentCategory : FullAuditedEntity<Guid> , IMayHaveTenant, IMultiLingualEntity<DocumentCategoryTranslation>
    {
		public int? TenantId { get; set; }

		[Required]
		[StringLength(DocumentCategoryConsts.MaxLoincCodeLength, MinimumLength = DocumentCategoryConsts.MinLoincCodeLength)]
		public string LoincCode { get; set; }
        public ICollection<DocumentCategoryTranslation> Translations { get; set; }
    }
public class DocumentCategoryTranslation : Entity, IEntityTranslation<DocumentCategory, Guid>
    {
        public string Name { get; set; }
        public DocumentCategory Core { get; set; }
        public Guid CoreId { get; set; }
        public string Language { get; set; }
    }
[AbpAuthorize(AppPermissions.Pages_DocumentCategories_Create)]
        private async Task Create(CreateOrEditDocumentCategoryDto input)
        {
            var documentCategory = ObjectMapper.Map<DocumentCategory>(input);

            if (AbpSession.TenantId != null)
            {
                documentCategory.TenantId = (int?)AbpSession.TenantId;
            }

            await _documentCategoryRepository.InsertAsync(documentCategory);
        }
public class CreateOrEditDocumentCategoryDto : FullAuditedEntityDto<Guid?>
    {
		[Required]
		[StringLength(DocumentCategoryConsts.MaxLoincCodeLength, MinimumLength = DocumentCategoryConsts.MinLoincCodeLength)]
		public string LoincCode { get; set; }
		public string Name { get; set; }
        public int? TenantId { get; set; }
    }
public static void CreateMappings(IMapperConfigurationExpression configuration, MultiLingualMapContext context)
        {
            configuration.CreateMultiLingualMap<DocumentCategory, Guid, DocumentCategoryTranslation, CreateOrEditDocumentCategoryDto>(context);

...

1 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    You can either ignore the mapping for the property Translations or map the translations as well (I don't think you want to map translations but here's a link for that <a class="postlink" href="https://stackoverflow.com/a/48931939">https://stackoverflow.com/a/48931939</a>)