CoolStorage field not equals filter

221 views Asked by At

I am working on a Windows Phone 7 application with an SQLite Local Database and I've stuck with it a bit.

I have several classes defined, each of them has a mapping set up and I wish to retrieve a list with some filterings. I have found many examples how to check for equal values but none for not-equal checks.

CSParameterCollection parameters = new CSParameterCollection();
        parameters.Add("@CurrentDate", currentDate);
        parameters.Add("@DirectionId", intVisszaut);
CSList<Trip> RouteTrips = Route.Trips.FilteredBy("Services.StartDate <= @CurrentDate and Services.EndDate >= @CurrentDate and Services." + DayOfWeek.ToString() + " = 1 and DirectionId = @DirectionId", parameters);

This filter works without any problems, but when I update it with the following, it fails:

(Services.CalendarDates.Date != @CurrentDate and Services.CalendarDates.Date.ExceptionType != 2)

CSParameterCollection parameters = new CSParameterCollection();
        parameters.Add("@CurrentDate", currentDate);
        parameters.Add("@DirectionId", intVisszaut);
CSList<Trip> RouteTrips = Route.Trips.FilteredBy("(Services.CalendarDates.Date != @CurrentDate and Services.CalendarDates.Date.ExceptionType != 2) and Services.StartDate <= @CurrentDate and Services.EndDate >= @CurrentDate and Services." + DayOfWeek.ToString() + " = 1 and DirectionId = @DirectionId", parameters);

Error code is: A first chance exception of type 'System.InvalidCastException' occurred in Vici.CoolStorage.WP7.dll

Services is a OneToOne, Services.CalendarDates is a OneToMany mapping. Do I use too many filter values or I do something wrong? It doesn't work by using <> either.

2

There are 2 answers

1
Stuart On BEST ANSWER

What is Services.CalendarDates.Date.ExceptionType - are you sure that can be compared to a numeric like 2?

To debug this:

  • try removing each part of your filter expression in order to identify which part is causing the failure
  • try linking to the CoolStorage source code - then you can see exactly what is failing (although this may be quite deep down in their stack and may feel a bit unreadable)
1
Philippe Leybaert On

The != syntax is not understood by SQLite. You should use <>