tags:

views:

250

answers:

2

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?
A: 

try union to get the both lists and join them

chugh97
+1  A: 

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 ... ;
David B