2012-07-16 108 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); 
}