2014-04-10 76 views
1

根據Valueinjecter與源和目標的映射通常使用命名約定完成。但它不適用於我的情況,我如何管理導航屬性的映射。Omu.ValueInjecter與EF中的導航屬性的映射

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提供

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; } 

如何將我的地圖導航性能與OMU.ValueInjector

回答

1

默認ValueInjecter映射具有相同名稱和類型的屬性

employeesDto.InjectFrom(employees); 

是不需要的,因爲它沒有做任何事情

這裏:

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

我沒有看到AttendanceTimeSlot和你MYEF之間的匹配性 所以MYEF不爲int slotID用於,時間跨度銀泰或時間跨度OutTime,所以上述線路返回新創建不變AttendanceTimeSlot

集合使用ValueInjecter的例子與EntityFramework(代碼第一)看看這個演示項目:http://prodinner.codeplex.com