在迭代LINQ to Entities结果集时,函数未知

时间:2014-09-23 19:58:26

标签: linq entity-framework linq-to-entities sql-server-ce entity-framework-6

当我执行此查询,然后尝试迭代它的结果时,我得到错误:

Dim recs = MonitorContext.DataRecords.OrderBy(Function(dr) dr.INDEX).ThenBy(Function(dr) dr.TIMESTAMP). _
Where(Function(dr) dr.TYPE = If(type, dr.TYPE)). _
Where(Function(i) i.INDEX > 2 And i.INDEX < 8). _
Where(Function(dr) dr.INDEX >= If(startIndex, dr.INDEX) And dr.INDEX <= If(endIndex, dr.INDEX)). _
Where(Function(dr) dr.TIMESTAMP >= If(startTime, dr.TIMESTAMP))

此处发生错误:

For Each rec As DataRecord In recs.ToList()

错误是:

EntityCommandExecutionException

  

{&#34;该函数的指定参数值无效。 [   参数#= 3,函数名称(如果已知)= case]&#34;}

我的数据记录如下:

Public Class DataRecord
    Public Property Id As Integer
    Public Property INDEX As Integer
    Public Property DeviceId As Integer
    Public Property TYPE As String
    Public Property TIMESTAMP As DateTime
    Public Property DI1 As Double
    Public Property DI2 As Double
    Public Property DI3 As Double
    Public Property DI4 As Double
    ...
    ...
    Public Property GSM As Double
    Public Property P As Double
    Public Property E As Double
    Public Property V As Double
    Public Property I As Double
End Class

当然是天生的。大约有二十Double名成员只是遗产,没有任何作用。 我很勇敢,可以通过EF 6在VB.NET中对SqlCe数据库执行此操作。

1 个答案:

答案 0 :(得分:0)

事实证明VB合并If()函数在某种程度上被误译了。当我更换

Where(Function(dr) If(startTime, dr.TIMESTAMP) >= startTime)

Where(Function(dr) startTime Is Nothing OrElse dr.TIMESTAMP >= startTime)

以及使用Where的所有其他If()条款,一切都运作得非常顺利。