2

最近我在我的一张表中添加了标识列:

this.Property(t => t.GatewayId)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

我试过这个答案:https ://stackoverflow.com/a/10552444/942637 。但是当我浏览我的网站时仍然出现以下错误:

Compiler Error Message: CS0433: The type
'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption' exists in both
'c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\09b33b19\15db599\assembly\dl3\626c4b05\eddd55c2_9c3ace01\EntityFramework.DLL'
and
'c:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll'

我正在使用 .NET 4 和 EF 5。当然,我的项目是指 EF 4.4,因为 .NET 4 支持的最新版本是 EF 4.4。我的网站在没有上述线路的情况下运行良好。

4

1 回答 1

2

安装 EntityFrameWork 对我有用。VS -> Tools -> NuGet Package Manager -> Package Manager Console,在包管理器控制台中输入:

安装包 EntityFramework(或最新版本 6.1.3)

于 2015-11-09T00:14:30.973 回答