I have following function in my code
public List GetpathsById(List id)
{
List paths = new List<
There's no magic: expression trees are translated into SQL queries which is what relational databases understand. You could do almost anything in an expression tree. Unfortunately not all operations are implemented. Consider the following example:
Presentation press = context
.Presentations
.Where(m => SomeCustomFunctionThatUsesUnmanagedPInvokeCode(m.PresId))
.FirstOrDefault();
What do you expect the generated SQL query to be?
That's the case with array indexers. They cannot be translated into SQL queries.
This being said, in your case, the following might be a little simpler:
public List GetpathsById(List id)
{
return
(from p in context.Presentations
where id.Contains(p.PresId)
select p.FilePath
).ToList();
}
The .Contains
method will be translated into a SQL IN
clause. This avoids sending multiple SQL queries to the database as you do in your example on each iteration.