2014-09-25 148 views
4

我首先使用Entity Framework 6.1.1和Code。 EF 6.1应该补充支持,为Index attribute,但无论是编辑器自动完成或编译器接受[索引]属性如:如何使用Entity Framework 6.1.1中的[Index]属性和Code First

[Index] 
public DateTime TimeOfSale { get; set; } 

所有项目引用指向DLL中的EF 6.1.1。

我也在运行SQL Server Compact Edition 4.0。

如何启用新的[Index]属性?

+1

你在这段代码中有相关的'using'语句吗? – DavidG 2014-09-25 16:29:17

+0

是的 - 我有使用System.ComponentModel.DataAnnotations; ,并且[Key]属性被接受。 – Mike 2014-09-25 16:31:20

+0

您的项目正在使用哪种版本的.NET Framework? – Masoud 2014-09-25 16:31:35

回答

8

虽然KeyAttribute位于System.ComponentModel.DataAnnotations名称空间中,但IndexAttribute类位于System.ComponentModel.DataAnnotations.Schema名称空间中。你很可能缺少以下using声明:

using System.ComponentModel.DataAnnotations.Schema; 
+0

我有同样的问题。用using语句添加Schema并没有帮助。 – 2015-01-11 23:04:33

+1

为我完美工作。但是我已经将我的软件包升级到了6.1.2。请注意,Visual Studio 2013社区版在框中使用6.0.something,您必须在使用帮助之前升级到EF的新版本。 – 2015-01-16 00:54:41

相关问题