0

im working with xml and linq.

I have 2 xml files both contain "ID" and "LANGUAGE"

I want to do a join based on where the both the ID and LANGUAGE are equal in both files I have something like this:

var data= 
from details in h_details.Descendants("ROW")

join inst in instance.XPathSelectElements("//Row")
on details.Element("ID").Value
equals inst.XPathSelectElement("Field[@Name=\'h_id\']").Value
and on details.Element("LANGUAGE").Value
equals inst.XPathSelectElement("Field[@Name=\'h_lang\']").Value

basically the "and" statement wont work, so how do i join based on 2 conditions?
raklos
  • 27,188
  • 58
  • 181
  • 291
  • This looks like a duplicate of http://stackoverflow.com/questions/373541/how-to-do-joins-in-linq-on-multiple-fields-in-single-join – dariom Jul 09 '09 at 09:57

2 Answers2

2

Anonymous types to the rescue.

var data=
  from details in h_details.Descendants("ROW")
  join inst in instance.XPathSelectElements("//Row")
  on new {
    x = details.Element("ID").Value,
    y = details.Element("LANGUAGE").Value
  } equals new {
    x = inst.XPathSelectElement("Field[@Name=\'h_id\']").Value,
    y = inst.XPathSelectElement("Field[@Name=\'h_lang\']").Value
  }
  select ... ;
Amy B
  • 105,294
  • 20
  • 131
  • 182
0

try union to get the both lists and join them

chugh97
  • 9,274
  • 25
  • 83
  • 134