Daily Archives: April 11, 2010

Funky Behavior NoTracking Query Entities

I’ve been using a lot of NoTracking queries to grab lists of data that I don’t need change tracked. It enhances performance and cuts down on resources. There are some nuances about these entities, however.

One of the interesting behaviors of EF4’s Lazy Loading is that even if you have entities that you have queried with NoTracking on, they will still lazy load related entities.

Unless you’ve read this somewhere (it’s on the ADO.NET team’s blog post which introduces lazy loading) or experienced it yourself (that’s me, since I had forgotten about that point in the blog post) you may not expect, or plan ahead, for this behavior.

You’d think that because the entity is not attached  to the context, it would not be able to pull this off. But it does. The related entity or collection will get automatically retrieved and the results are also detached and deep inside of the EntityObject sealed properties, there’s a flag that indicates they are NoTracking entities.

Another surprise is in store when you use NoTracking entities…again it’s only a surprise if you don’t happen to be aware of this behavior and it’s not what you might expect.

Normally when you join a detached entity to an attached entity, EF’s relationship span will kick in and automatically pull that detached entity into the context to be managed. However, this won’t happen with NoTracking entities and you’ll receive a very explicit exception message that explains this. You need to attach the “NoTracking” entity to the context first and then you can attach it to the other entity.

Ken Cox explores EF4’s Pluralization Service with a WCF Service

When I have done “what’s new in EF4” talks at user groups and conferences, I like to show off the new pluralization support in the EDM Wizard. I also like to have a little fun showing some cases where it doesn’t do so well. For example, it correctly singularized Breweries to Brewery, but uses the same rule on Movies, turning it to Movy.

The wizard uses a runtime feature referred to as the Pluralization Service which you can code against yourself.

Ken Cox recently built a WCF Service that uses the pluralization service to provide his own cloud plurlization service. And then ran a bunch of words against it. This is a lot easier than testing it in the designer! Here’s his blog post about the service: EF 4’s PluralizationService Class: A Singularly Impossible Plurality

A warning, though. Do not try to say the title of his blog post out loud or you may not be able to untwist your tongue until EF5 is released!

Today is last chance for EF Profiler 30% discount

Ayende has reminded us that Entity Framework Profiler’s Beta period ends tomorrow when it goes RTM. But that means the 30% discount also ends. It will go from $220US to $315US tomorrow.

I spend a lot of time looking at what’s going on in my database when using EF and the views that EFProf provide are indispensible. It’s organized by context instance and provides links back to the .NET code that executed each command.

I sure wish I had stock in this tool!

efprof