2

MVC4をインストールしました。

nuGet パッケージ マネージャーによると、私の EF のバージョンは 5.0.0 で、最終更新日は 2012 年 9 月 11 日です。

新しいコントローラーを作成しようとすると (コントローラーを右クリック -> [追加] -> [コントローラー])、エラー メッセージが表示され、新しいコントローラーを作成できません...

Could not load type 'System.ComponentModel.DataAnnotations.Schema.TableAttribute' 
from assembly 'EntityFramework, Version=4.1.0.0, Culture=neutral,     
PublicKeyToken=b77a5c561934e089'.

私は ASP.NET MVC を使い始めたばかりなので、誰かが私を解決するのを手伝ってくれるなら、それは大歓迎です.

パッケージ マネージャー コンソールから、次のように Entity Framework をアンインストールして再インストールしようとしましたが、効果がありませんでした。

PM> Uninstall-Package EntityFramework
Successfully removed 'EntityFramework 5.0.0' from GD.
Successfully uninstalled 'EntityFramework 5.0.0'.

PM> Install-Package EntityFramework
You are downloading EntityFramework from Microsoft, the license agreement to which is available at http://go.microsoft.com/fwlink/?LinkId=253898&clcid=0x409. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
Successfully installed 'EntityFramework 5.0.0'.
Successfully added 'EntityFramework 5.0.0' to GD.

Type 'get-help EntityFramework' to see all available Entity Framework commands.

PM> 

ご協力いただきありがとうございます。

アップデート:

私はこのチュートリアルに従っています。http://msdn.microsoft.com/en-us/data/gg685467.aspx

MVC4 は、DBContext を作成するこの方法を好まないようです...

Also there will be a new reference listed in the project references
called EntityFramework. This is the assembly that contains the Code
First runtime.

Add a new class to the Models folder and name it BlogContext. Modify
the class to match the following code: 

using System.Data.Entity;
namespace MVC3AppCodeFirst.Models 
{   
    public class BlogContext : DbContext   
    {
        public DbSet<Blog> Blogs { get; set; }
        public DbSet<Post> Posts { get; set; }
        public DbSet<Comment> Comments { get; set; }   
    } 
}

それはうまく構築されているので、何か不足していますか???

4

3 に答える 3

2

In your visual studio solution explorer, go to Models folder and open AccountModels.cs file. Comment out the following line

[Table("UserProfile")]

after commenting out, it will become

//[Table("UserProfile")]

Now compile and try to add a new controller.

于 2013-09-23T23:25:48.550 に答える
0

.NET 4.0 を対象にプロジェクトを作成する場合、EF はバージョン 4.4 を使用します。これは、.NET Framework 4 のコア コンポーネントがサポートできる範囲に限定された機能を備えた EF5 バージョンです (つまり、列挙型や空間型はサポートされません)。EF5 に付属するすべての新機能を使用する場合、MVC プロジェクトは 4.5 をターゲットにする必要があります。

于 2012-09-27T22:07:25.673 に答える
0

問題が解決しました...

  • Visual Studio 2010 をアンインストールする
  • Visual Studio 2012 Ultimate をインストールする

仕事終わり!!!

:)

于 2012-09-28T23:24:59.600 に答える