Search code examples
sqlitewindows-phone-7coolstorage

CoolStorage field not equals filter


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.


Solution

  • 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)