我正在尝试使用Linq创建XML,但是我有多个表嵌套如上,所以我必须创建从Table1中选择的具有明确ID的元素,依此类推,那么如何创建多个连接如上图?或者我应该如上所述迭代地重复和增加连接?
XDocument xDocument = new XDocument(new XElement("Table1",
from cs in Table1
join c in Table2
on cs.table1_id equals c.fk_table1_id
join ml in Table3
on c.table2_id equals ml.fk_table2_id
join s in Table4
on ml.table3_id equals s.fk_table3_id
select new XElement("Table2",
new XAttribute("NAME", c.name),
new XAttribute("TYPE", c.type),
new XAttribute("ID", c.id)),
//stucked here
new XElement("Table3",
select new XElement("Table3",
new XAttribute("WIDTH", ml.height),
new XAttribute("HEIGHT", ml.width)),