LINQ Query by Name
Posted on 2009-05-13
I have three tables...
What I basically want to do is to figure out a way to call item.Keys["Element Name"].Value so that I can use the Keys like an indexing system. Any ideas on a LINQ query that would express this?
It's kind of difficult to express. Essentially I need to get the index of the Keys as it is attached to another table where the Element.Name is equal to the expression.
So let's assume..
1 - "Stacey"
1 - "Age"
1 - 1 - 25 - 1
In my Model, I would see
item.Keys[ -index can go here to get the key- ].Value
I'm trying to find the best way to lookup the Index based on the Label I want. I am using the Elements table between Keys and Tags to enforce non-duplication due to typos and case-sensitivity. So the Elements is behaving like a dictionary of valid Key and Tag names.
I know of the .Single( e => Element.Name == "Age") approach, but I cannot seem to figure out how to translate this into the index filed. The problem is that the array will not always be indexed the same for every single user. Some of them might have "Age" at index 0, some might have it at Index 37.