EntityView2 VS FindMatches

Posts   
 
    
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 06-Mar-2008 19:50:53   

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?

tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 06-Mar-2008 19:58:52   

I think the act of posting a question always makes you think harder about your problem.

My problem isn't that the FindMatches method is returning the incorrect entity, I think. It's really that the for loop I'm using to get my matching entity is incorrect. I'm using a zero based loop and with count of one always returns 0 as the index. So the first entity in the collection is always return. In this case I am expecting the index to be 1 to bring back the second database row.

So how do I get the correct index to pass to the collection?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 06-Mar-2008 21:24:29   

tprohas wrote:

So how do I get the correct index to pass to the collection?

ScheduledVisitEntity scheduledVisit = this.scheduledVisits [ matches[i] ];
David Elizondo | LLBLGen Support Team