【问题标题】:Querying an Entity that has a varbinary field with LINQ使用 LINQ 查询具有 varbinary 字段的实体
【发布时间】:2012-06-05 18:41:12
【问题描述】:

当我尝试查询其中包含 varbinary 字段的实体时出现错误:

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

这是我的查询:

Dim query = From entity In db.Entity
        Where entity.Id= Id          
        Select entity.VarBinaryField

 If query.FirstOrDefault IsNot Nothing Then

     bytes = query.First.ToArray

     Return File(bytes, System.Net.Mime.MediaTypeNames.Application.Octet, "test")

 End If

当我检查查询不是空的时候,就会产生错误。

任何建议将不胜感激!

谢谢!

【问题讨论】:

  • entity.VarBinaryField 的类型是什么(在您的模型类中,而不是在数据库中)?我想知道你为什么申请ToArray。顺便说一句:您正在运行两次查询(FirstOrDefaultFirst 都命中数据库)。最好这样做:x = query.FirstOrDefault if x InNot Nothing Do something with x.

标签: vb.net asp.net-mvc-3 linq entity-framework-4.1


【解决方案1】:

我的 linq 查询中还有一些其他参数没有包含在内...正在从引发错误的数组中提取参数,而不是 varbinary 字段...

【讨论】:

    猜你喜欢
    • 2011-03-28
    • 2021-04-22
    • 2017-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多