[英]LINQ to Entities does not recognize the method 'System.String ToString(Int32)' method
I have search box which I want to return results based on TicketID. 我有搜索框,我想根据票证ID返回结果。 However, when trying to convert the TicketID to string to compare it against the search term string, I receive this error...
但是,当尝试将TicketID转换为字符串以将其与搜索字词字符串进行比较时,我收到此错误...
Here is my method: 这是我的方法:
public ActionResult Autocomplete(Ticket ticket, string term)
{
var searchTickets = db.Tickets
.Where(t => t.StatusID != 3 &&
Convert.ToString(t.TicketID).StartsWith(term))
.Take(10)
.Select(t => new
{
label = t.Summary
});
return Json(searchTickets, JsonRequestBehavior.AllowGet);
}
I have tried other suggestions on similar posts such as the SqlFunctions.StringConvert()
extension method, however, this throws a syntax error before the project is even built... 我在类似的帖子上尝试了其他建议,例如
SqlFunctions.StringConvert()
扩展方法,但是,这甚至在构建项目之前就引发了语法错误...
Any guidance will be appreciated. 任何指导将不胜感激。
try like this: 尝试这样:
Using System.Data.Objects.SqlClient;
var searchTickets = db.Tickets
.Where(t => t.StatusID != 3 &&
SqlFunctions.StringConvert((double)t.TicketID).StartsWith(term)
.Take(10)
.Select(t => new
{
label = t.Summary
});
With EF 4 you can use SqlFunctions.StringConvert
. 借助EF 4,您可以使用
SqlFunctions.StringConvert
。 There is no overload for int
so you need to cast to a double
or a decimal
. int
没有重载,因此您需要转换为double
或decimal
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.