在我的代碼LINQ到實體不承認我有以下功能數組索引
public List<string> GetpathsById(List<long> id)
{
List<string> paths = new List<string>();
for (int i = 0; i < id.Count; i++)
{
Presentation press = context.Presentations.Where(m => m.PresId == id[i]).FirstOrDefault();
paths.Add(press.FilePath);
}
return paths;
}
但是當我嘗試這一點,compiller得到錯誤這樣的。
LINQ to Entities does not recognize the method 'Int64 get_Item(Int32)' method, and this method cannot be translated into a store expression.
然後我嘗試做這樣的事情,一切正常。
public List<string> GetpathsById(List<long> id)
{
long x;
List<string> paths = new List<string>();
for (int i = 0; i < id.Count; i++)
{
x = id[i];
Presentation press = context.Presentations.Where(m => m.PresId == x).FirstOrDefault();
paths.Add(press.FilePath);
}
return paths;
}
所以我想知道爲什麼?在我的腦海裏,我無法得到任何答案。任何人都可以解釋這個矛盾嗎?
我也這麼認爲...... –
謝謝......但是他不能簡單地將該索引的值翻譯成SQL嗎? –
令人驚歎...爲什麼'包含'正在工作? –