Geeks With Blogs
Per Lundberg Random thoughts from a BizTalk developer April 2009 Entries
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> { /// ......

Posted On Wednesday, April 29, 2009 9:43 AM

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 ......

Posted On Wednesday, April 29, 2009 9:37 AM

Copyright © plundberg | Powered by: