I am creating a schedule with a DayPilot Lite control. I want to add additional information to each event but can't target properties through a join.
My datasource:
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;
}
Adding additional properties works if I target a property from the first table but not from a joined table:
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;
}
}
How do I target properties from joined tables?
The solution was to cast e.DataItem.Source
as the original type. I could then access the desired properties.
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;
}
}