Category Archives: linq

Hacking LINQ Expressions: Select With Index

First, a point of clarification: I use LINQ Expressions to mean (Language-INtegrated) Query Expressions (the language feature) rather than Expression Trees (the .NET 3.5 library in System.Linq.Expressions). So what do I mean by “Hacking LINQ Expressions”? Quite simply, I’m not … Continue reading 

Also posted in JavaScript, jQuery | 3 Comments

Simplifying LazyLinq

This is the fourth in a series of posts on LazyLinq, a wrapper to support lazy initialization and deferred disposal of a LINQ query context: Introducing LazyLinq: Overview Introducing LazyLinq: Internals Introducing LazyLinq: Queryability Simplifying LazyLinq Introducing LazyLinq: Lazy DataContext … Continue reading 

Also posted in NHibernate | 5 Comments

Introducing LazyLinq: Queryability

This is the third in a series of posts on LazyLinq, a wrapper to support lazy initialization and deferred disposal of a LINQ query context: Introducing LazyLinq: Overview Introducing LazyLinq: Internals Introducing LazyLinq: Queryability Simplifying LazyLinq Introducing LazyLinq: Lazy DataContext … Continue reading 

Also posted in TDD, Testing | 4 Comments

Introducing LazyLinq: Overview

This is the first in a series of posts on LazyLinq, a wrapper to support lazy initialization and deferred disposal of a LINQ query context, including LINQ to SQL’s DataContext: Introducing LazyLinq: Overview Introducing LazyLinq: Internals Introducing LazyLinq: Queryability Simplifying … Continue reading 

Also posted in TDD | 5 Comments

Using IDisposables 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 … Continue reading 

Also posted in NHibernate DDD | 15 Comments

Improve Your Code Golf Game with LINQ

I always enjoy a good coding challenge, and variations of code golf are most common. For the uninitiated, code golf provides a problem with the objective of providing a solution that requires the fewest keystrokes or lines. While production code … Continue reading 

Also posted in ActiveRecord, NHibernate, Repository Pattern | Leave a comment

Project-wide controller survey through reflection

I often lose track of all of the different controllers in our system, especially if I’m trying to see what existing conventions we have in place for the design of actions.  To get around this, I use a simple LINQ … Continue reading 

| 7 Comments

Visualizing LINQ expressions in the debugger

In Ben’s recent post on Fluent Route Testing in ASP.NET MVC, he recalled a problem we had when trying to figure out how to deal with an Expression<> once we have one.  Typically, I like to parse the Expression to … Continue reading 

| Leave a comment

Deferred execution gotchas

I was trying to be clever the other day and try to chain assertions on an array: [Test] public void This_does_not_work() { var items = new[] {1, 2, 3, 4, 5}; items .Each(x => x.ShouldBeLessThan(0)) .Each(x => x.ShouldBeGreaterThan(10)); } I … Continue reading 

| Leave a comment

Query Objects with Repository Pattern Part 2

As promised in my previous post, I’m going to make our query object a little more flexible and dynamic. First, this is what I really want to be able to do something like this: var customers = repo.FindBy( new TopCustomersWithLowDiscountQuery() … Continue reading 

| Leave a comment