Version: 2.5
Runtime: 2.0.50727
I having been playing around with these two methods of searching a collection and was wondering if anyone can explain why FindMatches is not doing what I expect.
I have the following two rows in a database table.
EventDescription StartTime EndTime
Event 1 description. 3/20/2008 9:00:00 AM 3/20/2008 12:00:00 PM
Event 2 description. 3/17/2008 3:00:00 PM 3/17/2008 6:00:00 PM
I am using the following two blocks of code to search for these events. This code is in the Calendar control DayRender event so it's looping through each day of the month and e.Day is the current day of month in the iteration.
PredicateExpression filter = new PredicateExpression();
DateTime startDate = e.Day.Date;
DateTime endDate = e.Day.Date.AddDays(1);
filter.Add(new FieldBetweenPredicate(ScheduledVisitFields.StartTime, null, startDate, endDate));
EntityView2<ScheduledVisitEntity> view = this.scheduledVisits.DefaultView;
view.Filter = filter;
if (view.Count > 0)
{
ScheduledVisitEntity scheduledVisit = view[0];
if (scheduledVisit != null)
{
DateTime startTime = (DateTime)scheduledVisit.StartTime;
DateTime endTime = (DateTime)scheduledVisit.EndTime;
e.Cell.Text = scheduledVisit.EventDescription + "<br />" + startTime.ToString("hh:mm tt") + " - " + endTime.ToString("hh:mm tt");
}
}
PredicateExpression filter = new PredicateExpression();
DateTime startDate = e.Day.Date;
DateTime endDate = e.Day.Date.AddDays(1);
filter.Add(new FieldBetweenPredicate(ScheduledVisitFields.StartTime, null, startDate, endDate));
List<int> matches = this.scheduledVisits.FindMatches(filter);
if (matches.Count > 0)
{
for (int i = 0; i < matches.Count; i++)
{
ScheduledVisitEntity scheduledVisit = this.scheduledVisits[i];
DateTime startTime = (DateTime)scheduledVisit.StartTime;
DateTime endTime = (DateTime)scheduledVisit.EndTime;
e.Cell.Text = scheduledVisit.EventDescription + "<br />" + startTime.ToString("hh:mm tt") + " - " + endTime.ToString("hh:mm tt");
}
}
The filter using EntityView2 works correctly and returns the correct entity for the correct day. The FindMatches method always returns the the first row Event 1. I would have expected that both groups of code would return exactly the same thing.
Why is FindMatches not returning the correct match for each day based on the between predicate?