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 Query
- Entity Framework How can I filter my results by a property of a navigation property?
- How can I return if an optional navigation property exists from an Entity Framework Query?
- Can I load hierarchical data with Entity Framework 4 using ".Include" and filter a Navigation Property based on some criteria
- How to make a property unique in Entity Framework Code First
- How can I get only records with a unique property using entity framework and linq?
- How can I do a Union all in Entity Framework LINQ To Entities?
- How to filter nested collection Entity Framework objects?
- How can I build Entity Framework queries dynamically?
- How can I extract a list of Tuple from a specific table with Entity Framework / LINQ?
- How can i write SQL update query with where clause in Entity Framework in C#
- How can I use Entity Framework on an object graph past a depth of 2 with MySQL Connector / NET?
- How can Entity Framework queries be reused (using methods)?
- How to include sorted navigation properties with Entity Framework
- Entity Framework - Selective Condition on Included Navigation Property
- How can I view the Entity Framework LINQ query plan cache?
- Entity Framework Core : how can I use DateDiff in Linq?
- How can I implement a LEFT OUTER JOIN in LINQ using lambda syntax on Entity Framework Core 2.0?
- Why is Entity Framework .ToList() with .Include very slow and how can I speed it up?
- Join vs Navigation property for sub lists in Entity Framework
- Entity framework - how to filter eager loaded navigational/relational properties?
- How to create a LINQ expression from an Entity Framework navigation property?
- Need Help Filtering A LINQ Query Using An Entity Framework Navigation Property
- How can avoid repeat same where in Entity Framework
- How to Create a Run-Time Computed (NotMapped) Value in Entity Framework Code First
- C#: How can I filter the results of an XML file based on a child element's attribute?
- Entity Framework - Get 'fake' navigation property within one query
- Entity Framework - Querying from ObjectContext vs Querying from Navigation Property
- How can I query using Entity Framework with an alpha-numeric comparison?
- How can I force a complete load along a navigation relationship in Entity Framework?
- How can I make a more efficient Entity Framework LINQ call than a nested loop
More Query from same tag
- Differences between VB TryCast and C# "as" operator when using LINQ
- Updating property values in one list with a property value average of matching items in another list
- EntityFramework .Take() Losing Performance Over Time
- NHibernate 3.1 Query equals
- Linq: Nullable Object must have Value
- Select Value from Dictionary if Key exists using LINQ
- How to handle linq statement returning exception when no file found
- C#/VB.Net How to collapse specific values in a list
- Grouping by an property in a list and the sorting these grouped elements by another property without affecting the original grouping
- LINQ query not working properly
- is there something faster than Enumerable.Except<TSource> Method?
- Linq to sql alias fails
- Checking for item in Generic List before using it
- Loop through array in linq query
- Refactor linq query and return a single after grouping
- LINQ with 2 WHERE condition
- Linq to get values from 2 list with one unique Id
- How can I store and retrieve data from a checkboxlist?
- How do I include only the question values here that have certain property values?
- Join and override a model value using LINQ
- C# Anonymous type foreach loop, a better way?
- implement repository in asp.net mvc 5
- Fast query to retrieve those records that has published date
- Allow caller to supply LINQ predicate without knowing value
- How to convert LINQ Query Generic List of Anonymous objects to IEnumerable<object>
- XML File with same elements
- How can we express the following code using query expression?
- Linq SQL Distinct at server side or app side?
- Select all rows from a model and have a nested json element as the Foreign key to another model with all rows selected
- how to get this grouped result using Linq