1

I am developing an ABP application with .net core 8. I have an entity Member as

 public class Member: AuditedAggregateRoot<Guid>
 {
     public string MembershipNo { get; set; }
     public string EmployeeNo { get; set; }
     public string FirstName { get; set; }
     public string MiddleName { get; set; }
     public string LastName { get; set; }
     public string Gender { get; set; }
     public DateTime DateOfBirth { get; set; }
     public DateTime EmploymentDate { get; set; }
     public string TelephoneNo { get; set; }
     public string PhyisicalAddress { get; set; }
     public string PostalAddress { get; set; }
     public string EmailAddress { get; set; }

 }

and I I have created DTO for this object as follows

public class MemberDto : AuditedEntityDto<Guid>
{
    public string MembershipNo { get; set; }
    public string EmployeeNo { get; set; }
    public string FirstName { get; set; }
    public string MiddleName { get; set; }
    public string LastName { get; set; }
    public string Gender { get; set; }
    public DateTime DateOfBirth { get; set; }
    public DateTime EmploymentDate { get; set; }
    public string TelephoneNo { get; set; }
    public string PhyisicalAddress { get; set; }
    public string PostalAddress { get; set; }
    public string EmailAddress { get; set; }

}

I have created an autoMapper profile as follos

public class AbpTestAutoMapperProfile : Profile
{
    public AbpTestAutoMapperProfile()
    {
        CreateMap<MemberDto, Member>().IgnoreAuditedObjectProperties() ;
        CreateMap<Member, MemberDto>().IgnoreAuditedObjectProperties();//.ForMember(dest => dest.Name, opt => opt.MapFrom(src => $"{src.FirstName} {src.MiddleName} {src.LastName}-({src.EmployeeNo})"));
        CreateMap<MemberDto, CreateUpdateMemberDto>();
        CreateMap<CreateUpdateMemberDto, Member>().IgnoreAuditedObjectProperties();
    }
}

I have configured autoMapper as follows

Configure<AbpAutoMapperOptions>(options =>
{
    options.AddMaps<AppModule>();
    options.AddProfile<AbpTestAutoMapperProfile>();
});

But when I try to evaluate the mapping

var member = await _memberRepository.GetAsync(id);

var mbm = ObjectMapper.Map<Member, MemberDto>(member);

I get an error : Can not map from given object ([ENTITY: MemberProxy] Id = 95a81b14-c881-4d59-5fcb-3a12b307b806) to AbpTest.Contracts.MemberDto, AbpTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.

The version of automapper is Volo.Abp.AutoMapper" Version="8.2.2

What might be the reason for this Error.

Regards

1
  • Try by removing IgnoreAuditedObjectProperties() once Commented Sep 1, 2024 at 15:25

1 Answer 1

1

I am assuming in the module "where you have configured automapper", you just need to decorate your class with [DependsOn(typeof(AbpAutoMapperModule))].

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.