I have a list of a model called results. I need to get those values from the results list which contain this particular string.
List<Search> results = new List<Search>();
results = db.Users.Select(f => new Search{ Name = f.Name, Type = f.OrganizationType.Name, County = f.County.Name }).ToList();
results = results.Where(w => (model.Name == null || w.Name.Contains(model.Name))).ToList();
While the first result query returns 5000 rows, the second one returns 0. What i am trying to do in the second query is if the Name is null or if the Name contains part of a string, add it to the results list. Am I missing something?
I did check a couple of links which basically asked me to do the same like Check if a string within a list contains a specific string with Linq
I have checked the value for model.Name and it shows up properly. Also the query works if there is no search string that is when Model.Name = null, I get all the records