15

ここで単純なものが欠けていると確信しています。いくつかのデータ注釈を使用するように指示する 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; }
    }
}

コンパイラは、最初の 2 つの注釈に問題はありませんが、気に入らないようです: [Column(TypeName="image")].

エラー:

  • タイプまたはネームスペース名「Column」が見つかりませんでした。

  • 型または名前空間名 'ColumnAttribute' が見つかりませんでした。

Visual Studio 2012 と Entity Frameworks 5 を使用しています。

助言がありますか?

4

2 に答える 2

33

Entity Framework 4.3.1では、で利用可能な namspace でColumnAttribute定義されています。したがって、その dll への参照と名前空間への using ステートメントがあれば、問題ありません。System.ComponentModel.DataAnnotationsEntityFramework.dll

Entity Framework 5では、System.ComponentModel.DataAnnotations.Schema名前空間にあるため、クラスにその参照を追加する必要があります。

using System.ComponentModel.DataAnnotations.Schema;

詳細については、こちらをご覧ください。

于 2012-10-06T10:00:01.320 に答える