0

I'm getting an error when using a join in a LINQ statement:

'HalftimeHomeGoals is not a member of anonymous type; it does not exist in the current context'.

         Dim HomeAllLP = (From a In db.Matches
                         Join b In db.MatchesLeagues On a.Id Equals b.Id
                         Where (a.HomeTeam = HomeTeam)
                         Order By a.Date Descending
                         Select a, b)



        For Each y In HomeAllLP
            If (y.HalfTimeHomeGoals > 0) Or (y.HalfTimeAwayGoals > 0) Then
                HFHGL2 = HFHGL2 + 1
            End If
        Next

It works fine if I only select a, but if I try and select my joined table as well it gives the error, so I can't access my joined table.

I have looked this up but don't understand any of the answers I've found so far and they are all in C#, I'm using VB.NET.

1
  • How about y.a.HalfTimeHomeGoals? Commented Nov 26, 2015 at 17:28

2 Answers 2

2

If you need to select both types, it is nevertheless a new type. you can select them in an object of anonymous type like

Dim HomeAllLP = (From a In db.Matches
                         Join b In db.MatchesLeagues On a.Id Equals b.Id
                         Where (a.HomeTeam = HomeTeam)
                         Order By a.Date Descending
                         Select New With {a, b})

Then in foreach you can acess properties of a or b like

For Each y In HomeAllLP
            If (y.a.HalfTimeHomeGoals > 0) Or (y.b.HalfTimeAwayGoals > 0) Then
                HFHGL2 = HFHGL2 + 1
            End If
        Next
Sign up to request clarification or add additional context in comments.

Comments

-1

Assuming that both classes Matches and MatchesLeagues contain a field/property named HalfTimeHomeGoals the following code should work:

For Each y In HomeAllLP
    If (y.a.HalfTimeHomeGoals > 0) Or (y.b.HalfTimeHomeGoals > 0) Then
       HFHGL2 = HFHGL2 + 1
    End If
Next

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.