views:

68

answers:

1

Here is a snippet of my (VB) LINQ:

From event_evn In xmlEvents.Descendants("event_evn") _
Join genre_gnr In xmlGenre.Descendants("genre_gnr") On event_evn.Element("evn_gnr_id") Equals genre_gnr.Element("gnr_id").Value _
Group Join eventdata_eda In xmlEventData.Descendants("eventdata_eda") On _
eventdata_eda.Element("eda_evn_id").Value Equals event_evn.Element("evn_id").Value And _
eventdata_eda.Element("eda_dty_id").Value Equals "15" _
Into edaList = Group _
From eventdata_eda In edaList.DefaultIfEmpty() _
Where _

I get an error in the last line with this message: "You must reference at least one range variable on both sides of the 'Equals' operator" How do I do a group join with multiple conditions, where one of these conditions is to comparing with a constant?

I found two places with the answer:
http://forums.asp.net/p/1209451/2127071.aspx#2127071
http://stackoverflow.com/questions/1122942/linq-to-sql-left-outer-join-with-multiple-join-conditions

However it is both in C# and I need it in VB.

Thanks in advance :)

+1  A: 

I had a similiar issue recently and I was able to get around it by declaring a variable of an anonymous type within the LINQ query to hold all the values I wanted to join on, and to use that new temporary variable in the join conditions so your snippet would look something like below:

From event_evn In xmlEvents.Descendants("event_evn") _
Let JoinVals = New With { .EvnId = event_evn.Element("evn_id").Value, _
                          .Fifteen = "15" } _
Join genre_gnr In xmlGenre.Descendants("genre_gnr") On event_evn.Element("evn_gnr_id")     Equals genre_gnr.Element("gnr_id").Value _
Group Join eventdata_eda In xmlEventData.Descendants("eventdata_eda") On _
eventdata_eda.Element("eda_evn_id").Value Equals JoinVals.EvnId And _
eventdata_eda.Element("eda_dty_id").Value Equals JoinVals.Fifteen _
Into edaList = Group _
From eventdata_eda In edaList.DefaultIfEmpty() _
Where _
lee-m