Daily Archives: March 20, 2010

Entity Framework POCO Template for .NET 3.5

UPON REFLECTION, I DECIDED THAT THIS POST WAS PRETTY MISGUIDED (must have been one of those days…).

So, for safety , I have removed it completely.

You *can* use T4 to customize the code generated for EntityObjects but if you begin with the T4 EntityObject template and replace .NET 4.0 specific logic with old style. FOr example ObjectSet & CreateObjectSet needs to be replaced by ObjectQuery and CreateQuery.

When I have some time, I will update this post to show how to do it.

VS2010 Gotcha: Inadvertently targeting the wrong framework

I love VS2010’s multi-framework targeting feature, yet it has bitten me in the rear-end more than once.

The problem is that I have created projects in .NET 3.5 without realizing it, then at some point, when something doesn’t work as expected, if I’m lucky I discover the mistake.

Typically, this happens after you have explicitly chosen .NET 3.5 as the target framework. Then every project after that will be .NET 3.5 until you explicitly choose .NET 4.0 again.

This morning that wasn’t the case. I was workign with a brand new installation of VS2010 RC and created a new class library then added to it an entity data model.

All of the features worked as expected except that I couldn’t generate a new code generation item.

Finally when I created a console app and attempted to add a reference to System.Data.Entity, I noticed that I was only seeing 3.0 and 3.5 versions of assemblies in the Add Reference dialog and realized my mistake (of creating the .NET 3.5 project).

This was in the middle of recording a session of DNRTV so turns out to be a really good lesson for viewers.

But I sure wish Visual Studio 2010 would warn me when I am creating a non .NET 4.0 project.