Per Lundberg

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

My Links

News

Archives

Post Categories

C#

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 [ C# ]

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 [ C# ]

ASP.NET 3.5/AJAX.NET-enabled datepicker snippet using the ASP:Calendar control
Looking for a simple datepicker that uses AJAX.NET (to avoid full-page postbacks), for your date fields? Look no further! I was on the same "hunt", and ended up writing my own code for it (inspired by other examples/code I was looking at). The code does all the work using ASP:NET, nothing is done using JavaScript. Below is the code for the solution. This could (and should) be made into a UserControl if you need to use in more than one place In the .aspx file, put this: (As you see, I am referencing...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Tuesday, March 24, 2009 8:50 AM | Feedback (4) | Filed Under [ C# ]

Trouble getting TargetInvocationException on your ASP.NET web application?`
Sometimes, you get pretty unclear exception messages. The message below is one example of such: Exception type: TargetInvocationException Exception message: Exception has been thrown by the target of an invocation. [...some stuff removed...] Stack trace: at System.RuntimeMethodHandle.... target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.... target, Object[] arguments,...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Thursday, March 19, 2009 1:26 PM | Feedback (2) | Filed Under [ C# ]

Powered by: