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;
context.Groups.Add(group);
context.SaveChanges();

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.

 
0
Kudos
 
0
Kudos

Now read this

C# Changes for the ASP.NET MVC Developer

C# 6 # Released Jul 20, 2015 Along with Roslyn Compiler, .NET 4.6, and Visual Studio 2015 Summary # C#6 focuses on streamlining common issues that require clumsy work-arounds that clutter the code. Null-conditional operator, string... Continue →