views:

268

answers:

3

I'm trying to do the following LINQ grouping, which works in the debugger (the results are populated in the GroupedOrders object. But VS 2008 gives me the following error at design time...

Name 'x' is not declared



            Dim GroupedOrders = (From m In thisConsultant.orders _
                      Group m By Key = m.commCode Into Group _
                     Select commCode = Key, orders = Group)

            For Each x In GroupedOrders

            Next


Public Structure consultantDetail 
    Public orders As List(Of orderDetail)
End Structure

Public Structure orderDetail
    Public transactionID As Integer
    Public qualifyingVolume As Decimal
    Public commissionableVolume As Decimal
    Public sponsorID As Integer
    Public orderDate As DateTime
    Public commCode As String
    Public commPercentage As Decimal
    Public discountPercent As Decimal

End Structure
A: 

hi, try to surround the Linq query with try-catch. Sometimes, there are error that are not catch directly by VS2008.

Garcia Julien
Well this particular error won't let me build the project. It doesn't recognize the X variable in the for each loop
Ed Sneller
Can you paste some of your code?
Garcia Julien
+1  A: 

Do you have Option Infer On?

Chris Haas
That was the problem. Thanks!
Ed Sneller
@Ed Sneller: In that case, you should mark this as "accepted answer" by clicking on the check mark next to the answer.
Heinzi
+1  A: 

My guess is that you have Option Strict On and Option Infer Off. To check these settings:

  1. Right-click on your project in the solution explorer
  2. Select Properties
  3. Select the Compile tab on the left
Dan Tao
Maybe you should also add what the settings *should* be. (Keep `Strict` on `On` and switch `Infer` to `On`.)
Heinzi