0

このスキーマのデータベースがありますが、従業員と診療所の両方にTimeSlotsのリストを追加することはできますか?はいの場合、そのマッピングの構成は何ですか。

ここに画像の説明を入力してください

ありがとう

4

1 に答える 1

2

いいえ、ナビゲーション プロパティClientEmployeeを含むエンティティが必要です。inエンティティが必要なTimeSlots場合は、related にアクセスするマップされていないプロパティを介してのみ実現できます。TimeSlotsEmployeeClinicClientEmployee

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

問題が見えますか?複数の関連を持つEmployeeことができ、それぞれが複数の TimeSlots を持つことができます - このプロパティは、関連するすべてのタイムスロットを提供します- 1 つだけが必要な場合は、メソッドが必要でas パラメータを渡します。ClinicClientEmployeesClientEmployeeClientEmployeesClientEmployeeId

public IEnumerable<TimeSlot> GetTimeSlots(int id)
{
    // ClientEmployees is mapped navigation property
    return ClientEmployees.Where(ce => ce.ClientEmployeeId == id)
                          .Select(ce => ce.TimeSlots);
}
于 2012-07-16T08:46:43.063 に答える