Per Lundberg

Random thoughts from a BizTalk developer
posts - 10, comments - 12, trackbacks - 0

My Links

News

Archives

Post Categories

LINQ

Instantiating a Dictionary from a LINQ projection, part 2
(This posting is a continuation of this blog posting.) If you want to implement this the OOP way, here you have the subclass code (which I'll use myself). using System.Collections.Generic; // Remember to set this to your proper namespace (or use a using statement in // the class with the LINQ projection) namespace MyNamespace { /// <summary> /// Extension methods for the Dictionary generic class. /// </summary> public class ImprovedDictionary<T1,T2... Dictionary<T1,T2> { ///...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Wednesday, April 29, 2009 9:43 AM | Feedback (1) | Filed Under [ .NET C# LINQ ]

Instantiating a Dictionary from a LINQ projection
Ever needed to instantiate a Dictionary from a LINQ projection? It is certainly doable, although not extremely straightforward. My first thought was to try and do this: var result = from o in ctx.Orders where o.ID = OrderID select new MyOrderClass { ID = o.ID, Created = o.Created, ExtraData = new Dictionary<string,string... Add("key1", o.Value1). Add("key2", o.Value2") }; If this would work, it would probably be the most clean-looking solution. The only problem with this though is that the...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Wednesday, April 29, 2009 9:37 AM | Feedback (2) | Filed Under [ .NET C# LINQ ]

Powered by: