开发者

Return a LINQ query with column values as name,value pairs

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.


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);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜