简体   繁体   English

LINQ to Entities无法识别方法'System.String ToString(Int32)'方法

[英]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没有重载,因此您需要转换为doubledecimal

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 LINQ to Entities无法识别方法'System.String ToString(Int32)' - LINQ to Entities does not recognize the method 'System.String ToString(Int32)' LINQ to Entities无法识别方法'System.String ToString(Int32)',并且该方法无法转换为商店表达式。“} - LINQ to Entities does not recognize the method 'System.String ToString(Int32)' method, and this method cannot be translated into a store expression."} LINQ to Entities无法识别方法'System.String ToString(Int32)'方法,并且此方法无法转换为存储表达式 - LINQ to Entities does not recognize the method 'System.String ToString(Int32)' method, and this method cannot be translated into a store expression LINQ to Entities无法识别方法'Int32 ToInt32(System.String)'方法 - LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method LINQ to Entities无法识别方法'Int32 IndexOf(System.String,System.StringComparison)'方法 - LINQ to Entities does not recognize the method 'Int32 IndexOf(System.String, System.StringComparison)' method LINQ to Entities 无法识别方法 'Int32 Int32(System.String)' 方法,并且此方法无法转换为存储表达式 - LINQ to Entities does not recognize the method 'Int32 Int32(System.String)' method, and this method cannot be translated into a store expression LINQ to Entities无法识别方法'Int32 CompareTo(System.String)'方法 - LINQ to Entities does not recognize the method 'Int32 CompareTo(System.String)' method LINQ to Entities 无法识别“System.String get_Item(Int32)”方法 - LINQ to Entities does not recognize the method 'System.String get_Item(Int32)' method LINQ to Entities无法识别方法'Int32 Parse(System.String)'方法, - LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method, LINQ to Entities无法识别方法'System.String GetMonthName(Int32)'方法 - LINQ to Entities does not recognize the method 'System.String GetMonthName(Int32)' method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM