Omer van Kloeten's .NET ZenProgramming is life, the rest is mere detailsLinq to SQL: ChangeConflictException With "WHERE 0 = 1"- April 28, 2008 I just finished debugging a very annoying error, where I kept getting a ChangeConflictException with the message "Row not found or changed" while trying to update my data. I found that there were no Member Conflicts in the exception, which seemed really weird to me. When I set the Log property on my context, I found that Linq to SQL was using UPDATE statements that looked like this: UPDATE dbo.MyTable SET Col1 = p0, Col2 = p1 WHERE 0 = 1 -- p0: Input ... -- p1: Input ... This was...http://weblogs.asp.net/okloeten/archive/2008/04/28/6139181.aspx Linq: FirstOrFallback- April 23, 2008 Sometimes you want to use FirstOrDefault, but the default value of T is a valid value that might get returned. If you used FirstOrDefault, you wouldn't know whether the value that you got is a valid first or the default fallback. I use FirstOrFallback to explicitly specify which fallback value I want, rather than always use default(T): public static T FirstOrFallback<T>(this IEnumerable<T> enumeration, T fallback) Check to see that enumeration is not null if (enumeration..http://weblogs.asp.net/okloeten/archive/2008/04/23/6123904.aspx Linq Extensions Release 2 Now on CodePlex- April 23, 2008 I've updated my long standing Linq Extensions project on CodePlex to .NET 3.5 RTM and added the latest extension methods. You can open bugs and feature requests using the Issue Tracker. If you want to download it, go and download the source code directly.http://weblogs.asp.net/okloeten/archive/2008/04/23/6123519.aspx Linq: The Missing ToDictionary Extension Method Overload- April 22, 2008 Enumerating over a Dictionary<TKey, TValue> you will get structs of type KeyValuePair<TKey, TValue>. Whenever you use the ToDictionary extension method, you are forced to specify how to get the key and value for each item, even if it's an enumeration of KeyValuePairs. Seems a bit redundant, doesn't it public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(this IEnumerable<KeyValuePair<TKey, TValue>> enumeration) Check to see that enumeration.http://weblogs.asp.net/okloeten/archive/2008/04/22/6121417.aspx Linq: SequenceSuperset- April 22, 2008 Here's another Linq method I wanted to share. This one takes two enumerations, enumeration and subset and checks to see whether subset exists in enumeration in its original order. I used the naming convention set by SequenceEqual. Examples: enumeration = (1, 2, 3, 4, 5); subset = (3, 4) ==> SequenceSuperset(enumeration, subset) = true enumeration = (1, 2, 3, 4, 5); subset = (6, 5) ==> SequenceSuperset(enumeration, subset) = false (6 does not exist in enumeration) enumeration..http://weblogs.asp.net/okloeten/archive/2008/04/22/6121373.aspx Help! My Web Application Throws an Insane Amount of TypeLoadExceptions!- April 17, 2008 One of the first things I noticed when I started debugging our web application was that at load I got an insane amount of these: A first chance exception of type 'System.TypeLoadException' occurred in System.Web.dll A first chance exception of type 'System.TypeLoadException' occurred in System.Web.dll A first chance exception of type 'System.TypeLoadException' occurred in System.Web.dll ... After digging into the code, I found out that during the loading process of controls,...http://weblogs.asp.net/okloeten/archive/2008/04/17/6107382.aspx |