0

I have a table named employee:

public class Employee
    {
        public int Id { get; set;}
        public int SupervisorId {get; set;}
        public int EmployeeStatusId{ get; set; }
        public EmployeeStatus EmployeeStatus{ get; set; }
    }

EmployeeStatus:

public class EmployeeStatus
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

There is EmployeeStatusDto which is the same as base class and EmployeeDto:

 public class EmployeeDto
    {
        public int Id { get; set; }
        public int SupervisorId {get; set;}
        public int StatusId { get; set; }
        public string StatusName { get; set; }
    }

AutoMapperConfig:

cfg.CreateMap<Employee, EmployeeDto>()
                    .ForMember(e => e.StatusId, m => m.MapFrom(p => p.EmployeeStatus.Id))
                    .ForMember(e => e.StatusName, m => m.MapFrom(p => p.EmployeeStatus.Name));

And getting it out of context class in service:

    employees = await _context.Employees.Where(x => x.SupervisorId == supervisorId).Include(x => x.EmployeeStatus).ToListAsync();
List<EmployeeDto> result = _mapper.Map<List<EmployeeDto>>(employees);

Problem I have is that StatusName and StatusId are nulls:

Status

What am I missing there?

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
Taxyy
  • 33
  • 4

0 Answers0