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();
Source: stackoverflow.com
Related Articles
- Entity Framework How can I filter my results by a property of a navigation property?
- Can I load hierarchical data with Entity Framework 4 using ".Include" and filter a Navigation Property based on some criteria
- Entity Framework - Selective Condition on Included Navigation Property
- Join vs Navigation property for sub lists in Entity Framework
- Need Help Filtering A LINQ Query Using An Entity Framework Navigation Property
- Entity Framework - Get 'fake' navigation property within one query
- Entity Framework - Querying from ObjectContext vs Querying from Navigation Property
- How can I return if an optional navigation property exists from an Entity Framework Query?
- Select list of objects from navigation property in Entity Framework Core
- Making a generic method to update entity framework many-to-many navigation property
- How to make a property unique in Entity Framework Code First
- Can't fetch Navigation Property in Entity Framework
- Entity Framework select few fields from navigation property object
- Entity Framework Navigation Property One-to-Many becomes One-to-One
- Entity Framework Include and Navigation Property
- Linq to Entity Filter using Navigation Property
- LINQ - Entity framework code first - Grouped results to custom class
- Entity Framework Core Invoke an Expression on Navigation property
- Entity Framework eager loading navigation property causes error when using user-defined type
- Entity framework navigation property is null
- Entity framework is trying to use a table that doesn't exist in the SQL for a navigation property
- Proper Linq Query for objects with many to many relation ship generated with code first entity framework
- Entity Framework Navigation Property preload/reuse
- Entity framework navigation property FirstOrDefault()
- How to filter nested collection Entity Framework objects?
- Entity Framework 6 Code First Custom Functions
- Filter the "Includes" table on Entity Framework query
- Entity Framework filter data by string sql
- EntityFramework 5 filter an included navigation property
- making a global filter for entity framework
- complex LINQ multiple tables with many to many
- Looping through DataTable & Constructing an Xml for each unique item
- Better way to Select to an async Func?
- Error when redefining a different xml Namespace to an existing alias using XElement with System.Xml.Linq
- Create Row_Number in linq query
- Better way to cleanly handle nested XML with LINQ
- Linq to DataTable (GROUP BY) when columns are not known
- Include not working in LINQ query but works in LINQ Fluent API
- Linq like predicate to sql string
- Group array of string arrays with LINQ
- Using .Distinct() on certain rows
- how to combine two columns Date and Time and compare it with given DateTime using linq
- net core API controller is returning incomplete json
- In LINQ to SQL, how can you convert a string to an int?
- LINQ query to retrieve from one table and then another
- Return data from related records with Linq to Entities
- LINQ: "Types in Union or Concat are constructed incompatibly."
- MVC: Repopulate filters form's fields without using Model
- two-dimensional array to an array in visual basic
- linq query with condition