tags:

views:

23

answers:

2

Hello,

I have a Table to store constants with columns(Name, Value). How do I go about getting the result of LINQ query in name value format like (Name = Value) so I can obtain the values like

Var thisVal = VarCollection("Name")

Hope this is clear.

Thanks in advance.

+1  A: 

I don't have a compiler handy to test this, but it'll go something like:

var VarCollection = (from t in Table
                    select new { t.Name, t.Value})
                    .ToLookup(t=>t.Name, t=>t.Value);

UPDATE: Upon reflection, I'm pretty sure that can be reduced to just:

var VarColelction = Table.ToLookup(t=>t.Name, t=>t.Value);
James Curran
Assuming his LINQ query has no where clause.
Blorgbeard
Table.Where(t=>t.SomeField==somevalue).ToLookup(....);
James Curran
This is my final query I went the dictionary way seemed much more familiar.var VarColelction = Table.ToDictionary(t=>t.Name, t=>t.Value);
fireBand
A: 

You could use a select to put them into a KeyValuePair and then put those into a Hash (basically a set of KeyValuePairs), then refer to the variables by name.

Eric