我收到以下錯誤,但我不知道如何重寫我的聲明? 任何想法?實體框架 - 字符串轉換錯誤
錯誤:
LINQ to Entities does not recognize the method 'System.String Convert(System.String)' method, and this method cannot be translated into a store expression
代碼:
public Client FindClientByMobile(string mobile, string accountId)
{
Client client = RepositorySet.Include("Account").FirstOrDefault(c => c.AccountId == accountId && !c.IsDeleted
&& ((Convert(c.TelephoneHome) == mobile) || (Convert(c.TelephoneMobile) == mobile) || (Convert(c.TelephoneWork) == mobile)));
return client;
}
public static string Convert(string mobile)
{
var filterNumber = from letter in mobile
where char.IsDigit(letter)
select letter;
StringBuilder number = new StringBuilder();
number.Append(filterNumber.ToArray());
return number.ToString();
}
該錯誤表示Linq需要將您的表達式轉換爲Sql語句。您的自定義'Convert'方法不可翻譯,因爲它是c#代碼,而不是數據庫服務器上也存在的。 – Igor
嗨,謝謝,但我已經說過這個問題,我問,但我不知道如何重寫我的聲明? –
電話號碼是字符串 –