EF5: Where are my DataAnnotations?

EF 4.x:

EF 4.1+ has a DataAnnotations namespace for the new EF related annotations. Most of them are related to database schema.

image

EF 5

Not even a DataAnnotations namespace in here. That’s because the annotations got incorporated into .NET 4.5.

image

 

.NET 4.5

A new namespace within System.ComponentModel.DataAnnotations: “Schema”

All of the EF schema annotations are in here now. MaxLength and MinLength are in the DataAnnotations namespace.

image

Added the following thanks to a suggestion from Cecil Phillip

If you are using EF5 with .NET 4, there is a special version of the Entity Framework assembly which actually has the version 4.4.*.

The EF related DataAnnotations *are* in this assembly but notice they’ve been organized into regular and schema as they are in  .NET 4.5.

image

  Sign up for my newsletter so you don't miss my conference & Pluralsight course announcements!  

11 thoughts on “EF5: Where are my DataAnnotations?

  1. Thanks for the fast reply,it seems the VS11 Preview i have has a problem, Uninstall in progress, will download the VS11 Beta, thanks again

  2. Hi, I installed EF 5 on .net 4.0 and the annotation NotMappedAttribute was ignored. Did you also get this problem?

  3. Hi Danimar,

    The NotMappedAttribute is part of .NET 4.5. When you combine EF5 with .NET 4, you won’t get the DataAnnotatations.Schema namespace.

  4. Hi, thanks for the reply.

    But I used NotMappedAttribute with .Net 4.0. I just updated the EF for version 5, and just this attribute is ignoring.

    Maybe still a bug in EF 5.

  5. you’re right. I just did this myself to a .NET 4 project. NotMapped "broke". Turns out that even with the assembly that goes with .NET 4, they moved these into Schema namespace also.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.