我想在我的項目中進行搜索功能。MVC LINQ與哪裏條件
目前,我想將十進制值轉換爲與searchString進行比較的字符串。
當我把這樣的:
public ActionResult Search(string searchString)
{
var product = from a in _db.Product.Include(a => a.Category)
select a;
if (!String.IsNullOrEmpty(searchString))
{
product = product.Where(a => a.model.ToUpper().Contains(searchString.ToUpper())
|| Convert.ToInt32(a.displaySize).ToString().Contains(searchString));
}
return View(product.ToList());
}
它有錯誤,
'LINQ到實體無法識別方法 'System.String 的ToString()' 方法'。
如何比較十進制值和字符串值?
你能幫我嗎?
謝謝。
重複的問題? http://stackoverflow.com/questions/10140634/mvc-where-condition-with-search-function – 2012-04-13 14:30:06
我通過'SqlFunctions.StringConvert(a.displaySize).Contains(searchString)'解決了這個問題。 – wholee1 2012-04-13 14:54:58