0

当我执行此查询,然后尝试和重复它的结果,我得到它们下面的错误:函数结果设置

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

{“该函数的指定参数值无效。 [ 参数#= 3的功能(如果知道的话)名称=情况下]“}

我的数据记录是这样的:

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成员只是传统和发挥不出作用。 我有足够的勇气来在VB.NET通过EF这样做对一个SQLCE数据库6

+0

看看生成的sql,使用recs的ToString方法,并抓住它并直接对数据库运行以找出发生了什么 – ErikEJ 2014-09-23 20:09:14

回答

0

原来,VB合并If()功能在某种程度上被误译了。当我更换

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

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

和所有使用If()其他Where条款,一切工作比较顺利。