public List<string> GetpathsById(List<long> id)
{
long[] aa = id.ToArray();
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 == aa[i]).FirstOrDefault();
paths.Add(press.FilePath);
}
return paths;
}
此代码引发以下异常:The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities.
但是,如果我提供x
代替aa[i]
有用。
Why?
要解决此问题,请使用临时变量:
var tmp = aa[i];
...
m => m.PresId == tmp
在你的 where 子句中你有
m => m.PresId == aa[i]
这是 lambda 表达式的一种表达方式。当它转换为表达式,然后转换为数据库查询时,它会找到aa[i]
,它是数组的索引。即它不将其视为常量。由于不可能将索引器翻译为数据库语言,因此会出现错误。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)