2017-02-02 55 views
0

我正在使用DayPilot Lite控件創建計劃。我想爲每個事件添加附加信息,但不能通過連接定位屬性。將屬性添加到DayPilot日曆並在EF數據源中加入

我的數據源:

protected IEnumerable<Schedule> GetUserSched(int userId) 
    { 
     var query = (from i in _context.UserScheduleMaps 
        where i.UserId == userId 
        select i.ScheduleId).ToList(); 

     var sched = (from i in _context.Schedules 
        join r in _context.Rooms 
        on i.RoomId equals r.RoomId 
        where query.Contains(i.ScheduleId) 
        select i).ToList(); 

     return sched; 
    } 

添加附加屬性的作品,如果我從第一臺目標的屬性而不是從連接表:

protected void calSched1_BeforeEventRender(object sender, DayPilot.Web.Ui.Events.Calendar.BeforeEventRenderEventArgs e) 
    { 
     if (e.DataItem.Source != null) 
     { 
      // e.DataItem["Room.RoomNameOrNumber"] ? 
      string location = e.DataItem["RoomId"] as string; 
      e.Html = e.Text + ", room: " + location; 
     } 
    } 

如何定位連接表的屬性?

回答

0

解決方案是將e.DataItem.Source作爲原始類型。然後我可以訪問所需的屬性。

protected void calSched1_BeforeEventRender(object sender, BeforeEventRenderEventArgs e) 
{ 
    if (e.DataItem.Source != null) 
    { 
     Schedule sched = (Schedule)e.DataItem.Source; 
     e.Html = e.Text + ", room: " + sched.Room.RoomNameOrNumber; 
    } 
}