I have the following code in my controller which gets the first result of a search with multiple words. Similar to the answer to this question: ASP:NET MVC multiple words in search
var items = from s in db.Items select s;
if (!string.IsNullOrEmpty(searchString) && !searchString.Any(x => Char.IsWhiteSpace(x)))
{
searchString.Trim();
items = items.Where(s => s.keywords.Contains(searchString) || s.notes.Contains(searchString)
}
else if (!string.IsNullOrEmpty(searchString) && searchString.Any(x => Char.IsWhiteSpace(x)))
{
searchString.Trim();
string[] strings = searchString.Split(' ');
var finalItems = new List<Items>();
foreach (var splitString in strings)
{
finalItems.Add(items.FirstOrDefault(s => s.notes.Contains(splitString)
|| s.keywords.Contains(splitString));
}
items = finalItems.ToList().AsQueryable();
return View(items.ToPagedList(pageNumber, pageSize));
}
I want to get all the matching results instead of the first match. Now when I try to change the .FirstOrDefault line to:
finalItems.Add(items.Where(s => s.notes.Contains(splitString)
|| s.keywords.Contains(splitString)
I get a 'cannot convert from 'System.Linq.IQueryable(MyProject.Models.Items)' to 'MyProject.Models.Items.
I've tried changing my items assignment to:
var items = from s in db.Items
select s as IQueryable(Items);
That seems to fix the issue but then it breaks all my s.keywords.Contains or s.notes.Contains with the error 'IQueryable(Items) does not contain a definition for keywords or notes and no extension method keywords or notes accepting a first argument of type IQueryable(Items) could be found'.