【发布时间】:2012-01-11 08:12:18
【问题描述】:
我的代码中有以下功能
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;
}
但是当我尝试这个时,编译器会出现这样的错误。
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;
}
所以我想知道,为什么?在我的脑海中,我无法为这种行为得到任何答案。谁能解释一下这个悖论?
【问题讨论】:
标签: c# linq asp.net-mvc-3 linq-to-entities