I have 3 XML files I can join by id.
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,
};
this code join CalendarFair and Executive now how can join FairCenter to this code
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>
Answer
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
};
It looks to me like you just need:
What was giving you problems with that? Note that you don’t really need all those
letstatements for the joins. I think it would be clearer as:That makes it really clear which elements you’re matching at each stage.
I assume you’ll want to use
din your projection, too…(You should probably look at casting
DateStartto aDateTimerather than using all those substring operations, by the way.)