外键属性不可用

时间:2015-02-12 13:54:59

标签: c# asp.net entity-framework

尝试使用MS Data Developer Center中列出的属性创建实体框架数据库模型时,我无法添加ForeignKey属性。我是否需要在代码中添加另一个using语句?

这是代码的副本:

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace Tester.Models
{
    public class MyClass
    {
        [Key]
        public int ID { get; set; }
        public string name { get; set; }
        public virtual List<Note> Notes { get; set; }
        public virtual List<Segment> Segments { get; set; }
    }

    public class Segment
    {
        public int ID { get; set; }
        public string name { get; set; }
        public virtual List<Note> segNotes { get; set; }
    }

    public class Note
    {
        public int ID { get; set; }
        public DateTime notetimestamp { get; set; }
        public string notestring { get; set; }
    }
}

1 个答案:

答案 0 :(得分:2)

using System.ComponentModel.DataAnnotations.Schema;

在.NET framework 4.5及更高版本中受支持

相关问题