I have the following code:
private IEnumerable<TrainScheduleViewModel> ListSelect(IQueryable<TrainSchedule> query, Page page)
{
List<TrainScheduleViewModel> viewModels = query
.Select(t => new TrainScheduleViewModel
{
Id = t.Id,
...
DaysOfWeek = BuildDaysOfWeek(t.DaysOfWeek)
})
.Page(page)
.ToList();
return viewModels;
}
private string BuildDaysOfWeek(IEnumerable<DayOfWeek> daysOfWeek)
{
var daysOfWeekStr = string.Empty;
return daysOfWeek.Aggregate(daysOfWeekStr,
(current, dayOfWeek) => current + ";" + CultureInfo.CurrentCulture.DateTimeFormat.DayNames[(int) dayOfWeek]);
}
In the debuger the query
have one object and DaysOfWeek
property is filled. But, in the BuildDaysOfWeek
method the collection is empty. Can you explain me why?
Two images:
PS.1 This is mapping for property:
<bag name="DaysOfWeek" cascade="all-delete-orphan" table="`ScheduleOnDaysOfWeek`">
<key column="`trainScheduleId`" not-null="true"/>
<element column="`dayOfWeek`" type="System.DayOfWeek" not-null="true" />
</bag>
If
DaysOfWeek
a child collection? If so you need to eager load that table in order to do that type of projection e.g.Or alternatively