Below #2 works when using the "MicrosoftProduct"
LIST, but fails when trying to get via the
"Lookup_PartNumbers" database table.
How can I get the below #2
working when using a database table ?
Steps
1. user types "10"
2. all PartNumbers that "startWith" 10.... from
Lookup_PartNumbers should appear, but nothing does
3. user types "100"
4. all PartNumbers that are exact matches from
Lookup_PartNumbers appear correctly
----------------------------------------------------------------------------
public JsonResult getData(string term)
{
/*
List<string> MicrosoftProduct = new List<string>();
MicrosoftProduct.Add("Office");
MicrosoftProduct.Add(".NET");
MicrosoftProduct.Add("Visual Studio");
MicrosoftProduct.Add("sql server");
MicrosoftProduct.Add("Windows7");
MicrosoftProduct.Add("Window8");
*/
var mySearchResults =
from p in db.Lookup_PartNumbers
//.Where(c => c.PartNumber.StartsWith(term, StringComparison.CurrentCultureIgnoreCase))
//above display below error
//LINQ to Entities does not recognize the method 'Boolean StartsWith(System.String, System.StringComparison)' method, and this method cannot be translated into a store expression.
//.Where(c => c.PartNumber.Contains(term))
//above does not error, but typing "10" displays nothing
//only after typing the FULL partNumber, "100", does the result display
//.Where(c => c.PartNumber.StartsWith(term))
//above does not error, but typing "10" displays nothing
//only after typing the FULL partNumber, "100", does the result display
.Take(10)
.Select(c => c.PartNumber + c.PartDescription)
.ToList()
select p;
List<string> getValues = mySearchResults.Where(item => item.ToLower().StartsWith(term.ToLower())).ToList();
// Return the result set as JSON
return Json(getValues, JsonRequestBehavior.AllowGet);
}