How To Limit String Field Lengths for LINQ to SQL

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

  • Share/Bookmark

Read Users' Comments (0)

Practical Understanding of Lambda Expressions in LINQ

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

  • Share/Bookmark

Tags: , , , ,

Read Users' Comments (0)

How to Use IDisposable with LINQ

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

  • Share/Bookmark

Tags: , , , ,

Read Users' Comments (0)

How to Share Parameters Between Lambda Expressions

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

  • Share/Bookmark

Tags: , ,

Read Users' Comments (1)

LINQ to SQL Tips and Tricks

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

  • Share/Bookmark

Read Users' Comments (0)

Thread Safe Generic Queue Class

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

  • Share/Bookmark

Read Users' Comments (0)

Using IEqualityComparer and Lambda Expressions

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

  • Share/Bookmark

Read Users' Comments (0)

How to Get a List of Files and Folders Without Directory.GetFiles Access Denied Error

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

  • Share/Bookmark

Read Users' Comments (0)

How to Create T-SQL CASE Statements With LINQ To SQL

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

  • Share/Bookmark

Read Users' Comments (0)

LINQ to SQL changes in .NET 4.0

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

  • Share/Bookmark

Read Users' Comments (0)

 Page 1 of 2  1  2 »