finance_teacher
asked on
LINQ -- easy "StartsWith" issue
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("Offi ce");
MicrosoftProduct.Add(".NET ");
MicrosoftProduct.Add("Visu al Studio");
MicrosoftProduct.Add("sql server");
MicrosoftProduct.Add("Wind ows7");
MicrosoftProduct.Add("Wind ow8");
*/
var mySearchResults =
from p in db.Lookup_PartNumbers
//.Where(c => c.PartNumber.StartsWith(te rm, StringComparison.CurrentCu ltureIgnor eCase))
//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(te rm))
//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.ToLow er())).ToL ist();
// Return the result set as JSON
return Json(getValues, JsonRequestBehavior.AllowG et);
}
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("Offi
MicrosoftProduct.Add(".NET
MicrosoftProduct.Add("Visu
MicrosoftProduct.Add("sql server");
MicrosoftProduct.Add("Wind
MicrosoftProduct.Add("Wind
*/
var mySearchResults =
from p in db.Lookup_PartNumbers
//.Where(c => c.PartNumber.StartsWith(te
//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(te
//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
// Return the result set as JSON
return Json(getValues, JsonRequestBehavior.AllowG
}
Because the Linq to SQL and Linq to Entity Framework work a little differently with strings please indicate which technology are you using.
ASKER
LINQ to Entities, but am willing to do anything to make it work.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.