Posted in CodeProject, LINQ | March 8th, 2010
We recently had an issue where a string value in our LINQ object was changed and became longer than the database field it represented. Whenever we tried to apply the changes to the database we would get an error. Now, I know that the correct solution is to implement the proper checks earlier on in [...]
Posted in CodeProject, LINQ | January 23rd, 2010
Lambda expressions are a powerful tool to writing quick, concise code. They can be used in numerous situations, most notably in conjuction with LINQ statements. A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types. All lambda expressions use the lambda [...]
Tags: expressions, lambda, lambda expressions, LINQ, linq c#
Posted in CodeProject, LINQ | December 5th, 2009
Objects that implement IDisposable are everywhere. The interface even gets its own language features (C#, VB, F#). However, LINQ throws a few wrenches into things: LINQ’s query syntax depends on expressions; using blocks are statements. When querying a sequence of IDisposable objects, there’s no easy way to ensure disposal after each element has been consumed. [...]
Tags: enumerator, expressions, ienumerable, linq to sql, using
Posted in CodeProject, LINQ | November 19th, 2009
When using Linq to objects, you will quickly feel the need to pass some parameters from a method to another but it’s not so easy because each Linq method is not calling the following one. In a Linq sequence, each method is using the result computed by the previous one. So, local contexts are not [...]
Tags: lambda, lambda expressions, linq c#
Posted in CodeProject, LINQ | August 29th, 2009
There are many little tips and tricks for LINQ to SQL which can make our lives easier, or improve the speed and efficiency of the generated code. Below are several tips and tricks I have found during my time as a LINQ developer. *Note: Some of these tips are for querying directly from the table. [...]
Posted in CodeProject, LINQ | August 11th, 2009
I've been doing a lot of mult-threading work, recently, using the standard Thead class, the Worker Queue, and the new PLINQ (Parallel LINQ). The problem with most of the built-in generic collections (Queue<>, List<>, Dictionary<>, etc), is that they are not thread safe. I created a library of thread safe collections which allow me to [...]
Posted in CodeProject, LINQ | July 26th, 2009
Anyone using LINQ to manipulate in-memory collections is probably also using plenty of lambda expressions to make things quite easy. These two additions were really meant for each other. One of our interns here recently ran into an interesting problem while using LINQ. As a relatively new user of .NET based languages, reference types caused [...]
Posted in CodeProject, LINQ | July 18th, 2009
I know the title is a bit long, but it descriptive of the problem. Recently I had need to retrieve a listing of files and folders given a root path. All worked well, until I tested on Vista and Windows 7 machines. When trying to browse the "Users" folder, I kept getting access denied errors [...]
Posted in CodeProject, LINQ | June 29th, 2009
I was recently asked to help with a LINQ To SQL query where the resulting T-SQL query was to have CASE statements. Having CASE statements in T-SQL queries is a common scenario but how do we it in LINQ To SQL? The solution is simple and straight-forward. As you will see below, using C#'s "Immediate [...]
Posted in CodeProject, LINQ | June 3rd, 2009
Well, it's official – LINQ to SQL is NOT dead in .NET 4.0. I'll say it again – LINQ to SQL is not dead. Damian G, a developer at Microsoft working on LINQ to SQL for .NET 4.0, recently made a list of changes that will be coming out in the next release of .NET. [...]