Upgrading EntityFramework

Does ApplyCurrentValues() ring a bell for you? If so you’re probably as excited as I am with the latest version of EntityFramework and the simplified APIs for interacting and manipulating object state.

At Wheelhouse almost all of our applications leverage EntityFramework in some way, so I recently embarked on a mission to upgrade us to the latest production release: EF6.1.3. Here are my chronicles.

Upgrade Methodology #

For All Versions #

Steps #

From EF4.* #

Code Changes #

Gotchas #

Meta Data Validation #

Meta Data class annotations are now validated on SaveChanges() whereas before they were only utilized by the javascript client-side libraries. This was a breaking change that caused headaches throughout our applications as methods with no changes suddenly started failing at runtime. Luckily we made testing a huge priority and were able to catch all of the significant issues.

Fixup Methods Are Gone #

We had a few places where we were relying on the Fixup behavior. Imagine a class like the following:

class Group { 
    int id { get; set; }
    name string { get; set; }
    Batches List<Batch> { get; set; }
class Batch {
    Group ParentGroup { get; set; }

There were cases where we’d create a Group object, and then create an association like this:

var group = new Group();
var batch = new Batch();
batch.Group = group;

With Fixup behavior, setting the Group property on the batch would also cause the Batch to be added to the collection of Batches on the Group object so that adding the group to the context would also insert all of the batches. Without the fixup behavior, the group would be added, but the batches would not be, and no exceptions would be thrown at that point.


Now read this

Migration plan from .NET 4 to .NET 4.6.1

At Wheelhouse, we have a few legacy applications running at various version of .NET from 4 up to 4.6. Re-target all projects to .NET 4.6.1. in a feature branch, building to catch usage of deprecated BCL features Review change log for... Continue →