2 つの日時に基づいて日付でフィルター処理しようとしています。MinTime
これらにMaxTime
基づいてフィルタリングしたいのですが、エラーが発生しています:
This function can only be invoked from LINQ to Entities
public static IEnumerable<ExclusionRule> GetExclusionRules(AppointmentTypes? apptType, string resourceName, TimeSpan? minTime, TimeSpan? maxTime, DayOfWeek? day) {
using (var db = new BusinessObjectContainer()) {
db.ExclusionRules.MergeOption = MergeOption.NoTracking;
var items = db.ExclusionRules;
int intDay = day.HasValue ? (int) day.Value : -1,
intApptType = apptType.HasValue ? (int)apptType.Value : -1;
var filteredApptType = apptType.HasValue ? items.Where(i => !i.t_AppointmentType.HasValue|| i.t_AppointmentType == intApptType) : items;
var filteredResource = string.IsNullOrWhiteSpace(resourceName) ? filteredApptType : filteredApptType.Where(i => !string.IsNullOrEmpty(i.ResourceName) && resourceName.ToLower().Equals(i.ResourceName.ToLower()));
IEnumerable<ExclusionRule> filteredMinDate;
if (minTime.HasValue) {
filteredMinDate = filteredResource.Where(i => (!i.MinTime.HasValue) || (EntityFunctions.CreateTime(i.MinTime.Value.Hour, i.MinTime.Value.Minute, 0) >= minTime.Value));
} else {
filteredMinDate = filteredResource;
}
IEnumerable<ExclusionRule> filteredMaxDate;
if (maxTime.HasValue) {
// this throws the exception
filteredMaxDate = filteredMinDate.Where(i => (!i.MaxTime.HasValue) || EntityFunctions.CreateTime(i.MaxTime.Value.Hour, i.MaxTime.Value.Minute, 0) <= maxTime.Value);
} else {
filteredMaxDate = filteredMinDate;
}
var filteredWeekDay= day.HasValue ? filteredMaxDate.Where(i => !i.t_DayOfWeek.HasValue|| i.t_DayOfWeek == intDay) : filteredMaxDate;
return filteredWeekDay.ToList();