2012-07-16 106 views

回答

2

不,你必须有ClientEmployee实体将包含TimeSlots导航属性。如果你想在EmployeeTimeSlotsClinic实体就可以实现,只有通过非映射属性将访问相关ClientEmployee

// This is from Employee or Clinic class 
[NotMapped] 
public IEnumerable<TimeSlot> TimeSlots 
{ 
    get 
    { 
     // ClientEmployees is mapped navigation property 
     return ClientEmployees.SelectMany(ce => ce.TimeSlots); 
    } 
} 

你看这个问题? EmployeeClinic可以有多个相关ClientEmployees每个ClientEmployee可以有多个时隙 - 这个属性会给你所有相关ClientEmployees所有时隙 - 如果你只想要一个你需要的方法和传递ClientEmployeeId作为参数:

public IEnumerable<TimeSlot> GetTimeSlots(int id) 
{ 
    // ClientEmployees is mapped navigation property 
    return ClientEmployees.Where(ce => ce.ClientEmployeeId == id) 
          .Select(ce => ce.TimeSlots); 
}