1

According to Valueinjecter mapping with source and Target are usually done with naming convention. But it doesn't work in my case , How could i manage mapping of navigation properties.

DTO

public class EmployeeDTO
{
    public long EmployeeId { get; set; }
    public long? LoginId { get; set; }
    public string EmpNumber { get; set; }
    public string FirstName { get; set; }
    public string CompanyEmail { get; set; }
    public string PersonalEmail { get; set; }
    public AttendanceTimeSlotDTO AttendanceTimeSlot { get; set; }

}

public class AttendanceTimeSlotDTO
{
    public int SlotId { get; set; }
    public TimeSpan InTime { get; set; }
    public TimeSpan OutTime { get; set; }
}

MYData Provider

  public List<EmployeeDTO> GetActiveEmployees()
    {
        var employees = UnitOfWork.EmployeeRepository.Get(employee => employee.IsActive, null, "AttendanceTimeSlot").ToList();


            //This work fine
        var employeesDto = employees.Select(x => new EmployeeDTO().InjectFrom(x)).Cast<EmployeeDTO>().ToList();
        employeesDto.InjectFrom(employees);

       // Not Working
          var result =employees.Select(e => new AttendanceTimeSlot().InjectFrom(e)).Cast<AttendanceTimeSlot>()
             .Select(x => new EmployeeDTO().InjectFrom(x)).Cast<EmployeeDTO>().ToList();

    }

MYEF

    public long EmployeeId { get; set; }
    public Nullable<long> LoginId { get; set; }
    public string EmpNumber { get; set; }
    public string FirstName { get; set; }


    public virtual ICollection<Attendance> Attendances { get; set; }
    public virtual ICollection<PermanentAddress> PermanentAddresses { get; set; }
    public virtual ICollection<TemporaryAddress> TemporaryAddresses { get; set; }
    public virtual AttendanceTimeSlot AttendanceTimeSlot { get; set; }

How would i map Navigation Properties with OMU.ValueInjector

Omu
  • 69,856
  • 92
  • 277
  • 407
Eldho
  • 7,795
  • 5
  • 40
  • 77

1 Answers1

1

by default ValueInjecter maps properties with same name and type

the line

employeesDto.InjectFrom(employees);

is not needed, because it doesn't do anything

here:

employees.Select(e => new AttendanceTimeSlot().InjectFrom(e))

I don't see any matching properties between AttendanceTimeSlot and your MYEF so MYEF doesn't has int SlotId, TimeSpan InTime or TimeSpan OutTime, so the above line return a collection of newly created untouched AttendanceTimeSlot

for an example of using ValueInjecter with EntityFramework (code first) have a look at this demo project: http://prodinner.codeplex.com

Omu
  • 69,856
  • 92
  • 277
  • 407