I have the following function in my code
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; }
But when I try to do this, the compiller gets an error like this.
LINQ to Entities does not recognize the method 'Int64 get_Item(Int32)' method, and this method cannot be translated into a store expression.
Then I try to do something like this and everything works fine.
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; }
So I wonder why? I cannot get an answer to this behavior in my mind. Can anyone explain this paradox?
c # linq linq-to-entities asp.net-mvc-3
Chuck Norris Dec 02 '11 at 9:02 2011-12-02 09:02
source share