maping type error

Asjad Butt 71 Reputation points
2023-02-06T12:34:05.2233333+00:00

im trying to create a get user by i method well not a user but an entity called branch and that entity has a foreign key called appuser now i want that when i call the get method it returns the entity branch as well as the data linked to it through the app user foreign key and for that i set up a dto and a maping profile which are

    public class Branch
    {
        public int Id { get; set; }
        public string BranchName { get; set; }
        public string City { get; set; }
        public string Address { get; set; }
        public int BranchCode { get; set; }
        public Guid AppUserId { get; set; }
        public AppUser AppUser { get; set; }
        public ICollection<AppUser> AppUsers { get; set; }
        public ICollection<StudyClass> studyClasses { get; set; }
        public ICollection<Student> Students { get; set; }
    }

that is tha branch entity and the dto is

    public class BranchDto
    {
        public int Id { get; set; }
        public string BranchName { get; set; }
        public string City { get; set;}
        public string Address { get; set; }
        public int BranchCode { get; set; }
        public Guid BranchAdminId { get; set; }
        /*        public Array BranchAdmin { get; set; }*/
        public string UserName { get; set; }
        public string FatherName { get; set; }
        public string Email { get; set; }
        public int PhoneNumber { get; set; }

    }

and now the mapping

 CreateMap<Branch, BranchDto>()
                .ForMember(dest => dest.BranchAdminId, opt => opt.MapFrom(src => src.AppUserId))
                /*.ForMember(dest => dest.BranchAdmin, opt => opt.MapFrom(src => src.AppUser))*/
                .ForMember(dest => dest.UserName, opt => opt.MapFrom(src => src.AppUser.UserName))
                .ForMember(dest => dest.FatherName, opt => opt.MapFrom(src => src.AppUser.FatherName))
                .ForMember(dest => dest.Email, opt => opt.MapFrom(src => src.AppUser.Email))
                .ForMember(dest => dest.PhoneNumber, opt => opt.MapFrom(src => src.AppUser.PhoneNumber))
                .ReverseMap();

but i get an error of unsuppoerted or missing maping configuration image

any idea why

Developer technologies ASP.NET ASP.NET Core
Developer technologies ASP.NET ASP.NET API
Developer technologies ASP.NET Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-02-07T07:30:57.7533333+00:00

    Hi @Asjad Butt

    From the error message we can see the error happens in the BranchController.cs file, check this file.

    The problem may be related to the mapping type, perhaps you are mapping IEnumerable<Branch> to a BranchDto or a Brach to IEnumerable<BranchDto>. You can change the map code and use the same type.

    Based on your code, I create a sample and add the mapper profile, the mapper works well, check the screenshot:

    User's image


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Dillion

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.