我們有一個字符串列表,我們需要按照該列表篩選結果。例子是找到誰具有與465,496,497或啓動(加X更多)核動力攻擊型潛艇的所有學生在一個Linq to Entities查詢中多次執行「like」運算符
List<string> list = GetPossibleStartsWithValues();
var qry = from student in entities.Students.WhereStartsWith(x=>x.SSN, list)
select new SearchedStudent
{
Name = student.Name,
SSN = student.SSN,
...
}
提供的代碼here接近我們所需要的,但我們不能找出如何啓發我們需要使用表達式類的StartsWith。
我不能得到代碼來編譯我得到的錯誤'投影'是一個'變量',但像'方法'一樣使用,我需要改變什麼? – johnnywhoop 2010-09-07 16:52:11
@johnnywhoop:哎呀。當我回家時會修復。 – 2010-09-07 17:02:13
是啊創建一個表達式會使它更快嗎?它看起來很慢但是可用。 – johnnywhoop 2010-09-10 17:20:02