2

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.

Bhawk1990
  • 126
  • 1
  • 5

2 Answers2

1

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)
Stuart
  • 66,722
  • 7
  • 114
  • 165
  • Seems that the expression filters were wrong. I have removed them all and built them up one-by-one and it worked that way. :P – Bhawk1990 Mar 06 '12 at 17:00
1

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

Philippe Leybaert
  • 168,566
  • 31
  • 210
  • 223