score:2

Accepted answer

Try running only w.Attendees.Any(a => a.Student.Name.IndexOf(searchString) and debugging it because Attendees could be null or empty, and the same is true for the Student property.

Also, in the off chance that your database isn't case insensitive, you should consider changing your code to reflect that:

w.Attendees.Any(a => a.Student.Name.ToLowerInvariant().Contains(searchString.ToLowerInvariant())

The case sensitiveness could be the source of your problems too.

score:-2

Try this:

List<Course> courses = db.Courses
    .Where(w => w.Title.Contains(searchString)|| 
           w.Description.Contains(searchString)  ||
           w.Attendees.Any(a => a.Student.Name.Contains(searchString))).ToList();

Related Articles