Thursday, June 22, 2006 3:57 AM
Mickey Williams
XLINQ and a Suggestion
If you're planning to be at my XLINQ talk this weekend at the San Diego CodeCamp, you might consider attending the C# 3.0 session first, where I'll be dicussing anonymous types, lambdas, and other topics. In the XLINQ talk, I'll be dicussing the differences between these two queries, and when one is more useful that the other:
from i in customers.Descendants("country").Select(x=>x.Value).Distinct()
orderby i
select new XElement("country", new XAttribute("name", i),
from c in customers.Element("customers").Elements("customer")
where i == (string)c.Element("country")
select new XElement("customer", c.Element("name"))
)
);
Versus this query:
from i in customers.Descendants("country").Select(country=>country.Value).Distinct()
join c in customers.Element("customers").Elements("customer")
on i equals (string)c.Element("country")
orderby i
select new XElement("customer", c.Element("name"),new XAttribute("country", i))
);
They both return XML content, but you'll want to understand how to shape the content to match your needs. More at the talk...