linq - 如何在join语句中组合条件

时间:2009-07-09 09:44:06

标签: c# linq xpath

我正在使用xml和linq。

我有两个xml文件都包含“ID”和“LANGUAGE”

我想根据两个文件中ID和LANGUAGE相等的位置进行连接 我有这样的事情:

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?

2 个答案:

答案 0 :(得分:2)

救援的匿名类型。

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

答案 1 :(得分:0)

尝试联合获取两个列表并加入它们