LINQ的前pression节点类型'ArrayIndex'不是在LINQ支持实体 [英] The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities

查看:342
本文介绍了LINQ的前pression节点类型'ArrayIndex'不是在LINQ支持实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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;
}

在此codeI有一个exaption:'ArrayIndex'不是在LINQ支持实体LINQ前pression节点类型

In this code i have a an exaption: The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities.

买的时候我不是AA [我]我用x其工作正常。

Buy when I instead of aa[i] I use x it is working.

为什么?

推荐答案

要解决这个问题用一个临时变量:

To fix this use a temporary variable:

var tmp = aa[i];
...
m => m.PresId == tmp


在您的where子句中有


In your where clause you have

m => m.PresId == aa[i]

这是前$ P $的pssing拉姆达前pression的一种方式。当被转换为一个前pression,然后转换成数据库的查询它找到的氨基酸由[i] ,它是一个索引到一个数组。 即。它不会把它作为一个常量。由于一个索引到你的数据库语言的翻译是不可能的它给人的错误。

which is a way of expressing a lambda expression. When that is converted to an expression, then converted into a query on your database it finds the aa[i], which is an index into an array. i.e. it doesn't treat it as a constant. Since a translation of an indexer to your database language is impossible it gives the error.

这篇关于LINQ的前pression节点类型'ArrayIndex'不是在LINQ支持实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆