LINQ to Entities不支持LINQ表达式节点类型'ArrayIndex'

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_35491254/article/details/88814158

错误代码示例:
for (int i = 0; i < id.Count; i++)
{
Presentation press = context.Presentations.Where(m => m.PresId == aa[i]).FirstOrDefault();
paths.Add(press.FilePath);
}

错误提示:
The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities.

解决方法:
这是一种表达lambda表达式的方式。当它被转换成一个表达式,然后转换成你的数据库查询时,它会发现aa[i],这是一个数组的索引。即它不会将其视为常量。由于将索引器转换为数据库语言是不可能的,因此会导致错误.

正确代码:
for (int i = 0; i < id.Count; i++)
{
var tmp = aa[i];
Presentation press = context.Presentations.Where(m => m.PresId == tmp).FirstOrDefault();
paths.Add(press.FilePath);
}

猜你喜欢

转载自blog.csdn.net/qq_35491254/article/details/88814158