请参阅以下内容:扩展方法在LINQ的声明
public Content GetContentByPageTitle(string pageTitle)
{
return _db.Contents.FirstOrDefault(
x => hnUrlHelper.UrlSafe(x.PageTitle).Equals(pageTitle)
);
}
public class hnUrlHelper
{
public static string UrlSafe(string value)
{
if (!string.IsNullOrEmpty(value))
{
value = value.Replace("Š", "s");
value = value.Trim().ToLower();
value = value.Replace(" ", "-");
value = Regex.Replace(value, @"[^A-Za-z0-9-_]", "");
return value.Trim().ToLower();
}
return string.Empty;
}
}
Server Error in '/' Application. LINQ to Entities does not recognize the method 'System.String UrlSafe(System.String)' method, and this method cannot be translated into a store expression.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NotSupportedException: LINQ to Entities does not recognize the method 'System.String UrlSafe(System.String)' method, and this method cannot be translated into a store expression.
Source Error:
我试图找出Linq的语句中UrlSafe方法。这显示如下错误。 有没有人知道如何解决这个问题?
赞赏。非常感谢。它完美的工作。 – Tun 2013-05-02 14:13:25