This project is read-only.

A gotcha...

Nov 2, 2011 at 11:18 AM

A small gotcha I discovered this morning that I thought I'd document.  (Per other thread, perhaps this should move to some other medium in due course).

Anyway... this is perhaps predictable, but if you mix-and-match versions of Entity Framework across projects, then things don't work.

What I have is a solution with a RunMVC projects A, referencing code-first Model projects B, and C.  Because there are composite keys, the model projects have to reference EntityFramework to follow the idiom:

[Key, Column(order = 1)]
public virtual String MyKeyPart { get; set; }

These projects A, B, and C were all referencing EF 4.1.10715.0.

This morning I added a new project D, and used NuGet to add the EF reference.  What I didn't notice is that EF has just been bumped up to v4.2.0.0.  The error I got "Unable to determine composite primary key ordering " was because the Column attribute from the EF v4.2 assembly didn't seem to be being picked up.

To fix the problem, I uninstalled EF using the NuGet package manager, and then used the Package Manager Console in VS to install the previous version of EF manually using:

> install-package EntityFramework -version 4.1.10715.0

Hope that's of use.

Nov 2, 2011 at 11:42 AM

Thanks, that's useful.  Just as an added clarification for others:  this applies when working CodeFirst only.  In fact, it is not at all clear from the NuGet listing that the 'Entity Framework' NuGet package being installed is not actually the Entity Framework (which now forms a core part of VS), but is in fact the old 'Entity Framework Code First CTP'.  (We did think about doing separate NuGet packages for the NakedObjects.ProgrammingModel, with and without the Code First dependency, but decided that that was unnecessary fiddle.)

The issue you raise is a general one, though, that could apply to any third party dependency.

"Per other thread, perhaps this should move to some other medium in due course".   Yes.  We need to extract tips like this into, say, a structured 'Help and Tips' section (also FAQ).