請參閱以下內容:擴展方法在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