并且也不在Linq Query vb.net中工作

时间:2012-01-26 01:57:00

标签: vb.net linq-to-sql

我有一个结构数组(aryShooters())。我需要确定他们在哪个帖子以及他们是否有效。如果他们是,那么我想存储他们所在的索引。如果帖子未填充,则数组中该点的索引设置为-1。我遇到的问题是,在我的查询中,我检查它然后使用AndAlso,不会使线路的其余部分短路。

这是我设置索引的地方:

Dim p1i as integer = -1
Dim p1i as integer = -1
Dim p1i as integer = -1
Dim p1i as integer = -1
Dim p1i as integer = -1
For j as integer = 0 to UBound(aryShooters)
    If aryShooters(j).active = true Then
        Select Case aryShooters(j).post
            Case 1
                p1i = j
            Case 2
                p2i = j
            Case 3
                p3i = j
            Case 4
                p4i = j
            Case 5
                p5i = j
        End Select
    End If
Next

然后我立即调用我的查询。它只是最后5行搞砸了。

Dim pos
pos = From p In db.Banks
            Where p.ShootId = shootIdProp And p.EventId = eventNo _
            And ((p.FlightNo >= (CurFlight - kd)) And (p.FlightNo <= (CurFlight + (x-1) + ku))) _
            And ((p.SectionNo Like lowsec) Or (p.SectionNo like upsec)) _
            And p.Inactive = False And (((p.P1 like p1a And p.P2 Like p2a And p.P3 Like p3a And p.P4 Like p4a And p.P5 Like p5a) And resetFlags = False) _
            Or (( p.NmbrOpenPosts >= numberShooters) And resetflags = True)) _
            And ((((p1i > -1) AndAlso ((Math.Abs(aryShooter(p1i).Ydg - p.HcpYds1) <= perTrap) Or (p.HcpYds1 = 0.0))) And _
             (((p2i > -1) AndAlso ((Math.Abs(aryShooter(p2i).Ydg - p.HcpYds2) <= perTrap) Or (p.HcpYds2 = 0.0))) And _
             (((p3i > -1) AndAlso ((Math.Abs(aryShooter(p3i).Ydg - p.HcpYds3) <= perTrap) Or (p.HcpYds3 = 0.0))) And _
             (((p4i > -1) AndAlso ((Math.Abs(aryShooter(p4i).Ydg - p.HcpYds4) <= perTrap) Or (p.HcpYds4 = 0.0))) And _
             (((p5i > -1) AndAlso ((Math.Abs(aryShooter(p5i).Ydg - p.HcpYds5) <= perTrap) Or (p.HcpYds5 = 0.0))))
            Select p

编辑 - 好吧,我修好了。只是在位置0添加了一个空白点。它仍然可以引用它但从未真正读过它。

1 个答案:

答案 0 :(得分:0)

也许这会有所帮助(我不是vb专家):
我想这一行:

pos = From p In db.Banks

应该是这样的:

pos = From p In db.Banks _ 

我认为这一行:

Or (p.HcpYds5 = 0.0))))
            Select p

应该是这样的:

Or (p.HcpYds5 = 0.0))) _ 
            Select p

最后一个if语句你有很多未使用的括号。在那里我认为声明:

 And ((((p1i > -1) AndAlso ((Math.Abs(aryShooter(p1i).Ydg - p.HcpYds1) <= perTrap) Or (p.HcpYds1 = 0.0))) And _
             (((p2i > -1) AndAlso ((Math.Abs(aryShooter(p2i).Ydg - p.HcpYds2) <= perTrap) Or (p.HcpYds2 = 0.0))) And _
             (((p3i > -1) AndAlso ((Math.Abs(aryShooter(p3i).Ydg - p.HcpYds3) <= perTrap) Or (p.HcpYds3 = 0.0))) And _
             (((p4i > -1) AndAlso ((Math.Abs(aryShooter(p4i).Ydg - p.HcpYds4) <= perTrap) Or (p.HcpYds4 = 0.0))) And _
             (((p5i > -1) AndAlso ((Math.Abs(aryShooter(p5i).Ydg - p.HcpYds5) <= perTrap) Or (p.HcpYds5 = 0.0))))
            Select p

应该是这样的:

And _ 
             ((p1i > -1) AndAlso ((Math.Abs(aryShooter(p1i).Ydg - p.HcpYds1) <= perTrap) Or (p.HcpYds1 = 0.0))) And _
             ((p2i > -1) AndAlso ((Math.Abs(aryShooter(p2i).Ydg - p.HcpYds2) <= perTrap) Or (p.HcpYds2 = 0.0))) And _
             ((p3i > -1) AndAlso ((Math.Abs(aryShooter(p3i).Ydg - p.HcpYds3) <= perTrap) Or (p.HcpYds3 = 0.0))) And _
             ((p4i > -1) AndAlso ((Math.Abs(aryShooter(p4i).Ydg - p.HcpYds4) <= perTrap) Or (p.HcpYds4 = 0.0))) And _
             ((p5i > -1) AndAlso ((Math.Abs(aryShooter(p5i).Ydg - p.HcpYds5) <= perTrap) Or (p.HcpYds5 = 0.0))) _ 
            Select p