2012-10-06 149 views
11

我確定我在這裏錯過了一些簡單的東西。 我想要遵循一個Code First Entity Framework教程,它告訴我使用一些數據註釋。無法找到類型或命名空間名稱'列'

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.ComponentModel.DataAnnotations; 

namespace Model 
{ 
    public class Destination 
    { 
     public int DestinationId { get; set; } 

     [Required] 
     public string Name { get; set; } 
     public string Country { get; set; } 
     [MaxLength(500)] 
     public string Description { get; set; } 

     [Column(TypeName="image")] 
     public byte Photo { get; set; } 

     public List<Lodging> Lodgings { get; set; } 
    } 
} 

編譯器不具有與前兩個註釋的所有問題,但它似乎並不喜歡:[Column(TypeName="image")]

錯誤:

  • 類型或命名空間名稱 '列' 找不到。

  • 無法找到類型或命名空間名稱'ColumnAttribute'。

我使用Visual Studio 2012和Entity框架5.

有什麼建議?

+0

我認爲photo屬性必須是字節數組而不是字節。 –

回答

25

實體框架4.3.1ColumnAttributeSystem.ComponentModel.DataAnnotations namspace,這是在EntityFramework.dll可用來定義。所以,如果你有一個對該dll的引用以及對該命名空間的using語句,那麼你應該沒問題。

實體框架5,它在System.ComponentModel.DataAnnotations.Schema namspace,所以你需要添加一個對你的類的引用。

using System.ComponentModel.DataAnnotations.Schema; 

您可以閱讀關於它的更多詳細信息here

+0

添加參考後,我必須做一個完整的清理和重建。只是重建不起作用。 –

+0

您的修補程序適用於我,但上面的鏈接似乎已損壞。 – RussellH

+0

@RussellH謝謝!修復了斷開的鏈接 – Shyju

相關問題