This is a migrated thread and some comments may be shown as answers.

Query not returning correct results

2 Answers 55 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stijn
Top achievements
Rank 1
Stijn asked on 28 Nov 2016, 10:03 AM

When fetching objects from the database using a where clause, the results aren't always 100% complete. See the example below:

var missingcourseList = this._database.GetAll<Course>().Where(o => o.Id == 1386).ToList();
missingcourseList = missingcourseList .Where(o => o.IsValidated
                                 && (!o.Private || o.EmployerRegistrations.Any(p => p.Employer == zone))
                                 && (o.Organiser == null || o.Organiser != zone)
                                 && o.Education is InheritedCourse
                                 && o.CourseEvents.Max(p => p.Date) >= DateTime.Today)
                     .OrderBy(o => o.CourseEvents.Min(p => p.Date))
                     .ToList();
 
var publicCourses = this._database.GetAll<Course>()
                     .Where(o => o.IsValidated
                                 && (!o.Private || o.EmployerRegistrations.Any(p => p.Employer == zone))
                                 && (o.Organiser == null || o.Organiser != zone)
                                 && o.Education is InheritedCourse
                                 && o.CourseEvents.Max(p => p.Date) >= DateTime.Today)
                     .OrderBy(o => o.CourseEvents.Min(p => p.Date))
                     .ToList();

 

The missingCourse is not included in the publiccourses query, even though it's using the exact same linq where clause.

2 Answers, 1 is accepted

Sort by
0
Stijn
Top achievements
Rank 1
answered on 28 Nov 2016, 10:32 AM

FYI: Putting '&& o.Education is InheritedCourse' in commentary makes the 'publiccourses' list return the missing one, while the missing one IS 100% sure of type 'InheritedCourse' (provenby the fact it works in the missingcourse query above).

 

Modifying the code to '&& o.Education.GetType() == typeof(InheritedCourse)' makes no difference.

0
Stijn
Top achievements
Rank 1
answered on 07 Feb 2017, 08:31 AM
Bump
Tags
General Discussions
Asked by
Stijn
Top achievements
Rank 1
Answers by
Stijn
Top achievements
Rank 1
Share this question
or