I wrote this one recently, mind you I am well aware that is is going overboard - but the entire architecture of the application is a mess so I'm just having fun reading the xml config files.
I had already solved this in a conventional and, dare I say "cleaner" way, but I challenged myself to find out how to write the query such that I don't make duplicate states dictionaries - share it for the tags in the respective symbol group.
var xmlTags = config.Element("Tags").Elements("Tag");
var xmlSymbols = config.Element("Symbols").Elements("Symbol");
var tagStates =
from tag in xmlTags
group tag by tag.Attribute("Symbol").Value into tagGroup
join symbol in xmlSymbols
on tagGroup.Key equals symbol.Attribute("Name").Value
// grouping so that each respective states dictionary is shared instead of creating duplicates
let states = symbol.Elements("State").Select(st => new
{
Name = st.Attribute("Name").Value,
Value = (double)st.Attribute("Value")
}).ToDictionary(st => st.Value, st => st.Name)
from tg in tagGroup
select new
{
TagId = (string)tg.Attribute("TagId"),
Symbol = (string)symbol.Attribute("Name"),
States = states
};