简体   繁体   English

LINQ to Entities不支持实体框架'ArrayIndex'

[英]Entity Framework 'ArrayIndex' is not supported in LINQ to Entities

in my SQL Server DB table, I have the binary column type. 在我的SQL Server数据库表中,我有binary列类型。

I can't execute the query, why ? 我无法执行查询,为什么?

var data = (from x in model.MyTable
            where x.BinaryColumn[0] == 1
            select x).FirstOrDefault();

I get the The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities error 我得到The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities错误The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities

These expressions are translated to SQL queries, and this is one of the things you cant do. 这些表达式被转换为SQL查询,这是您无法做到的事情之一。 Take a look here for more detail: LINQ To Entities doesn't recognize array index 请查看此处了解更多详细信息: LINQ To Entities无法识别数组索引

In TSQL the SUBSTRING function can be used on binary / varbinary . 在TSQL中, SUBSTRING函数可用于binary / varbinary

Somewhere define: 在某处定义:

[DbFunction("SqlServer", "SUBSTRING")]
public static byte[] SubString(byte[] field, int start, int length)
{
    throw new NotSupportedException("Direct calls are not supported.");
}

then 然后

var data = (from x in model.MyTable
            where Substring(x.BinaryColumn, 1, 1) == new byte[] { 1 }
            select x).FirstOrDefault();

If you're willing to change your query a bit, this would work: 如果您愿意稍微更改您的查询,这将有效:

var data = (from x in model.MyTable
            where SqlFunctions.CharIndex(new byte[] { 1 }, x.BinaryColumn) == 1
            select x).FirstOrDefault();

See MSDN 请参阅MSDN

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 LINQ to Entities不支持'ArrayIndex' - 'ArrayIndex' is not supported in LINQ to Entities LINQ to Entities不支持LINQ表达式节点类型'ArrayIndex' - The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities LINQ to Entities 不支持 LINQ 表达式节点类型“ArrayIndex” - The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities 错误:LINQ to Entities不支持LINQ表达式节点类型'ArrayIndex' - Error: The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities 在Where子句中使用Contains会导致错误:LINQ to Entities不支持'ArrayIndex' - Using Contains in a Where clause is causing error: 'ArrayIndex' is not supported in LINQ to Entities 实体框架中的LINQ to Entities不支持LINQ表达式节点类型“Invoke” - The LINQ expression node type 'Invoke' is not supported in LINQ to Entities in entity framework 在Linq.IQueryable错误上调用.Any():“ LINQ to Entities不支持Linq表达式节点类型'ArrayIndex'” - Calling .Any() on Linq.IQueryable error: “The Linq expression node type 'ArrayIndex' is not supported in LINQ to Entities” LINQ到实体-实体框架 - LINQ to Entities - Entity Framework 具有Linq to Entities性能的实体框架 - Entity framework with Linq to Entities performance ASP.NET-实体框架-LINQ to Entities仅支持无参数构造函数和初始化程序 - ASP.NET - Entity Framework - Only parameterless constructors and initializers are supported in LINQ to Entities
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM