У меня есть 3 XML-файла, к которым я могу присоединиться по идентификатору.
var test = from b in doc.Descendants("CalendarFair")
let start = b.Element("DateStart").Value
where
start.Substring(0, 2) == dateNow.Substring(0, 2) &&
start.Substring(6, 4) == dateNow.Substring(6, 4)
let id1 = b.Element("IdExecutive").Value
join c in doc1.Descendants("Executive")
on id1 equals c.Element("Id").Value
select new
{
Title = b.Element("Title").Value,
DateStart=b.Element("DateStart").Value,
DateEnd=b.Element("DateEnd").Value,
NameExecutive = c.Element("NameExecutive").Value,
};
этот код присоединяется CalendarFair
и Executive
теперь, как можно присоединить FairCenter
к этому коду
var test = from b in doc.Descendants("CalendarFair")
let start = b.Element("DateStart").Value
where start.Substring(0, 2) == dateNow.Substring(0, 2) &&
start.Substring(6, 4) == dateNow.Substring(6, 4)
let id1 = b.Element("IdExecutive").Value
join c in doc1.Descendants("Executive")
on id1 equals c.Element("Id").Value
join d in doc3.Descendants("FairCenter")
on ........ //by id
select new
{
Title = b.Element("Title").Value,
DateStart=b.Element("DateStart").Value,
DateEnd=b.Element("DateEnd").Value,
NameExecutive = c.Element("NameExecutive").Value,
telExecutive = c.Element("Tel").Value,
websiteExecutive = c.Element("Website").Value
};
FairCenter.xml
<FairCenters>
<FairCenter>
<Name>c1</Name>
<Id>1</Id>
</FairCenter>
<FairCenter>
<Name>c2</Name>
<Id>1</Id>
</FairCenter>
Executives.xml
<Executives>
<Executive>
<NameExecutive>e1</NameExecutive>
<Id>1</Id>
</Executive>
<Executive>
<NameExecutive>e2</NameExecutive>
<Id>2</Id>
</Executive>
</Executives>
CalendarFair.xml
<CalendarFairs>
<CalendarFair>
<DateStart>09/09/2011</DateStart>
<DateEnd>07/15/2011</DateEnd>
<Title>f1</Title>
<IdExecutive>1</IdExecutive>
<IdCenter>1</IdCenter>
</CalendarFair>
<CalendarFair>
<DateStart>07/14/2011</DateStart>
<DateEnd>07/20/2011</DateEnd>
<Title>f2</Title>
<IdExecutive>5</IdExecutive>
<IdCenter>2</IdCenter>
</CalendarFair>
</CalendarFairs>
Ответ
var test = from b in doc.Descendants("CalendarFair")
let start = b.Element("DateStart").Value
where start.Substring(0, 2) == dateNow.Substring(0, 2) && start.Substring(6, 4) == dateNow.Substring(6, 4)
let id1 = b.Element("IdExecutive").Value
let id2 = b.Element("IdCenter").Value
join c in doc1.Descendants("Executive")
on id1 equals c.Element("Id").Value
join d in doc3.Descendants("FairCenter")
on id2 equals d.Element("Id").Value
select new
{
Title = b.Element("Title").Value ,
DateStart=b.Element("DateStart").Value,
DateEnd=b.Element("DateEnd").Value,
NameExecutive = c.Element("NameExecutive").Value,
telExecutive = c.Element("Tel").Value,
websiteExecutive = c.Element("Website").Value,
NameCenter = d.Element("Name").Value
};