Query not returning correct results

Thread is closed for posting
3 posts, 0 answers
  1. Stijn
    Stijn avatar
    8 posts
    Member since:
    Mar 2016

    Posted 28 Nov 2016 Link to this post

    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. Stijn
    Stijn avatar
    8 posts
    Member since:
    Mar 2016

    Posted 28 Nov 2016 Link to this post

    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.

  3. Stijn
    Stijn avatar
    8 posts
    Member since:
    Mar 2016

    Posted 07 Feb 2017 Link to this post

    Bump
Back to Top