2014-09-25 132 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

相關問題