1
votes
Dim distinctJoints As IEnumerable
distinctJoints = From row In spotsTable.AsEnumerable()
                                        Group row By Key = row("FUNCJOINTCODE") Into Group
                                        Select Key, Group

_evaluatedJointsCount = (From row In spotsTable.AsEnumerable()
                        Group row By Key = row("FUNCJOINTCODE") Into Group
                        Select Key, Group).Count()

'Process each joint
For Each currentJoint In distinctJoints
    Dim currentJointKey As String = currentJoint.Key

For the above code currentJoint.Key is showing error of late binding after option strict is on. Could you please help me out of this.

1
No it doesn't. You used the wrong type - IEnumerable isn't the same as IEnumerable<T>. In this case there's no reason to define distinctJoints separately, just write Dim DistinctJoins = From ... and type inference will use the correct type - Panagiotis Kanavos

1 Answers

0
votes

First, let me congratulate your for moving your code towards Option Strict On! It might be some work in the beginning, but it pays off in the long run since a lot of errors will be found at compile-time rather than at run-time.

That said, let's look at your problem. Here:

Dim distinctJoints As IEnumerable

you declare distinctJoints as a non-generic IEnumerable. A non-generic IEnumerable returns items of type Object when iterated over. The type Object does not contain a Key method. This is why you get a compile-time error.

Since your LINQ query returns a generic IEnumerable of an anonymous type, the solution is to use type inference instead. Activate Option Infer On (if you have not already done so) in your project properties and let the compiler infer the correct data type:

' Dim distinctJoints As IEnumerable <-- remove this
Dim distinctJoints = From row In spotsTable.AsEnumerable()
                     Group row By Key = row("FUNCJOINTCODE") Into Group
                     Select Key, Group