我已經使用LINQ麻煩,我會在例子來解釋:LINQ到實體包含()和嵌套查詢
我有一個名爲僱員數據庫表,得到了名字和姓氏列, 和方法搜索職工它獲取名稱列表列表作爲參數,在此列表中的元素名稱格式像這樣的「弗雷德刻錄」,或this1「死神」, 已經tryed這些方法沒有運氣= [
//just all employees
var allData = from emp in Context.Employee select emp;
var test1 = from emp in allData
where(emp.FirstName + " " + emp.LastName).Contains
("" + ((from n in nameList select n).FirstOrDefault()))
select emp;
var test2 = (from emp in allData
where (emp.FirstName + " " + emp.LastName)
== ((from n in nameList select n).FirstOrDefault())
select emp);
var test3 = from emp in allData
where (from n in nameList select n).Contains
(emp.FirstName + " " + emp.LastName)
select emp;
第一個和第二個查詢給出:{「無法創建一個類型'閉包類型'的常量值。只有原始類型('suc 「異常
和第三:{」LINQ to Entities does not recognized the method'布爾Contains [String](System.Collections.Generic.IEnumerable`1('Int32,String,and Guid')is supported in this context。 [System.String] System.String)」的方法,而這種方法不能被翻譯成店表達。「}
會很高興聽到您的建議:)
謝謝!
p.s.
是的,我知道它可以在列表中拆分名稱並分別進行比較,但仍然好奇爲什麼不能使用這些查詢。