我正在使用LINQ to Entities從SQL中選擇數據。LINQ Store表達式中不支持的方法
這裏是我的發言
var employee = from p in _context.employee
select p;
employee = employee.Where(p =>
Helper.RemoveSpecialCharacters(p.IdentificationNumber).
Equals(Helper.RemoveSpecialCharacters(search.IdentificationNumber)));
var Results = employee.ToList();
我使用RemoveSpecialCharacters方法,我寫信給兩側對比無特殊字符進行比較。
這裏我得到錯誤,Linq-> Entity不支持「RemoveSpecialCharacters」方法,它不是有效的存儲表達式。
我知道它不能被翻譯成SQL。但是,如何使用LINQ進行這種比較?
RemoveSpecialCharacters方法
public static string RemoveSpecialCharacters(string str)
{
char[] arr = str.Where(c => (char.IsLetterOrDigit(c))).ToArray();
str = new string(arr);
return str;
}
我怎樣才能把這個LINQ讓SQL理解,如果方法名被轉換爲LINQ店那麼也許。
順便說一句,var employee = from _context.employee select p;'被翻譯成var employee =(_context.employee);'(C#語言規範版本5.0,7.16.2.5選擇子句) 。 – Philippe
理想情況下,您應該能夠創建一個MethodCall表達式,爲您的IQueryable查詢工作,它只是無法翻譯方法,從'Expression Tree'編譯'Func'時 –
使用'Regex.Replace'檢出代碼 –