Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading from EF 4 to EF 5

My application is based on .NET 4.0 and EF 4. I'm now looking at upgrading to the latest versions.

  • Are there any breaking changes or behavioral differences that may adversely affect my application?
  • How easy is the upgrade path? Does upgrading to EF 5 require any code changes or other work?
  • Are there any new features related to code-first that would be worth upgrading for?
like image 798
SimpleUser Avatar asked Aug 27 '12 07:08

SimpleUser


2 Answers

EDIT: First of all, EF 5/.NET 4.5 has a major concern in that is will never support Windows XP or Server 2003 (or earlier). If you need support for either of those OS's, use EF 4.4 with .NET 4.0, which has none of the fun new stuff.

Also, I hit a (simple) breaking change relating to DataAnnotations moving namespaces:

Entity Framework 4.1 thru 4.3 included additional data annotations in the System.ComponentModel.DataAnnotations namespace in the EntityFramework assembly. In .NET 4.5 these annotations were moved to be part of the .NET Framework in the System.ComponentModel.DataAnnotations.Schema namespace of the System.ComponentModel.DataAnnotations.dll assembly. If you are using EF 4.x and targeting .NET 4.5 this results in two data annotations with the same name in different assemblies.

See http://blogs.msdn.com/b/adonet/archive/2012/02/29/ef4-3-1-and-ef5-beta-1-available-on-nuget.aspx, which still applies in EF 5 RTM.

In short, I had to add:

using System.ComponentModel.DataAnnotations; // had this already
using System.ComponentModel.DataAnnotations.Schema; // needed this one

to a zillion places.

like image 54
Scott Stafford Avatar answered Oct 25 '22 00:10

Scott Stafford


How easy is the upgrade path? Does upgrading to EF 5 require any code changes or other work?

You'll have to upgrade to .net 4.5 for most new features to work.

Are there any new features related to code-first that would be worth upgrading for?

Not exactly related to code-first, because it's crosscutting, but still worth mentioning: Enum support.

like image 45
Serg Rogovtsev Avatar answered Oct 25 '22 01:10

Serg Rogovtsev