Daily Archives: February 1, 2008

Why I don’t travel in the winter

I change my mind daily about going to MIX.

I WANT TO GO TO MIX. The registrations are dwindling and it will soon be sold out.

But I don’t want to deal with this:

SOUTH BURLINGTON — Today’s ice storm has caused numerous delays and cancellations this afternoon at Burlington International Airport, airport officials said.

Between about 3 and 5 p.m., there are expected to have been two delayed and two canceled arrivals, and another four or five delays and two canceled departures from the airport, said airport Facilities Manager Brian Searles.

“Right now, it’s really all about where flights are coming from,” said Searles. “We’re operational here.”

Searles said a continuing ice-build up could force the airport to close at some point this evening.

People should call the the airlines for more information on their flight, Searles said.

[source today’s burlington free press]

This article doesn’t even mention the winds that have been howling the past 6 hours. It’s not much fun to be in a plane that is landing in high winds on ice covered runways. Been there done that.

And then there’s always the fun at O’Hare. Last April we sat onthe runway for 2 hours when we landed at O’Hare, got on another plane and sat there for 3 hours before we took off. Bah!

Clever LINQ to Entities query trick? Or is it a bug?

In my post about rewriting Brad Abram’s MVC + Entity Framework example in VB, I pointed out a better way to query a collection of objects and return their entity references (eg, query products and bring along the category information) without writing a scary query filled with references, checks for nulls, etc.

But there was something bothering me about the query.

I went from this (Brad’s)

List<Product> products =TheProducts.Where(c => c.Category.CategoryName == category).ToList();//prepare the view by explicitly loading the categoriesproducts.FindAll(p => p.Category == null).ForEach(p => p.CategoryReference.Load()); 

To this

     var _prod = Northwind.Categories.
              Where(c => c.CategoryName == id).
              OrderBy(c => c.CategoryName).
              Select(c => c.Products).
              First().ToList();

Which gives the same effect of ending up with a set of products and being able to drill into product.category.categoryname, etc.

But that query represents something that Entity Framework is not supposed to do, and I asked Danny Simmons about it.

Entity Framework will not perform actions that you did not request. I selected only products in my projection, yet I also got back categories. It was convenient, but it was against the promise of EF. I didn’t ask for categories.

In the end, a bug was filed, because indeed, that shouldn’t be happening.

However, it’s still VERY easy to explicitly tell EF to bring along a collection (eg if I query categories I can say “and give me those products while your at it) or an entity ref (query products and ask for the category) by using Include.

Here’s the same query for the MVC view even simpler.

    var _products = Northwind.Products.Include(“Category”).
        Where(p => p.Category.CategoryID == 1).ToList();

There are other ways to achieve this as well, but for this scenario, this is the most streamlined (as far as I know ;-)).