Failure after upgrading project from .NET 4.0 to .

2019-07-05 05:49发布

问题:

I have a working website targeting .Net 4.0 and entity framework 4.3.1. After installing .Net 4.5 ( with Visual Studio Express 2012 ) I can compile the website on Visual Web Developer Express 2010 but when i try to navigate to

http://localhost/ 

I get this error:

CS0246 “The type or namespace name 'MaxLength' could not be found” on

[Column("titulo"), Required(), MaxLength(150)]
Línea 13:         public string Titulo { get; set; }

I have this using statement:

using System.ComponentModel.DataAnnotations;

The application pool on IIS is configured for .Net 4.0.

I tried updating Entity framework to 4.4 ( from Nuget ) and added this using statement:

using System.ComponentModel.DataAnnotations.Schema;

But then the error is:

CS0246 “The type or namespace name 'Column' could not be found”

Any suggestion to solve the problem?

Thx.

回答1:

To make this work you have to do the following:

  1. Open NuGet package manager and find in the Installed packages tab the Entity Framework package. Uninstall it.

  2. Now Go to the Online tab and search for Entity Framework. Hit install. Now your project should reference the correct version of EF that is 5.0 instead of 4.4.0 (the version I had before intalling this new version).

Hope it helps.

For more info, take a look here: http://forums.asp.net/t/1779042.aspx/1



回答2:

May be you need to add some references, which you using in your solution(right click on your project - Add Reference...)