同一表EF6中主键的外键引用

时间:2015-08-27 21:02:56

标签: c# .net entity-framework

我在MVC项目中有类,我使用了Entity Framework 6.每个人都有一个Master(public class Person { [Key] public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Email { get; set; } [ForeignKey("Person")] public int Master_Id { get; set; } public virtual Person Master { get; set; } public virtual ICollection<Person> Persons { get; set; } } ),它引用了同一个表(Person表中的主键)。我的方式不起作用......解决方案是什么?

from django.views.generic.dates import BaseDateListView


class YourClass(BaseDateListView):

    def get_dated_queryset(self, **lookup):
        return queryset with specific date range

1 个答案:

答案 0 :(得分:0)

public class Person
{
    [Key]
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Email { get; set; }

    public int? MasterId { get; set; }

    [ForeignKey("MasterId")]
    public virtual Person Master { get; set; }

    public virtual ICollection<Person> Persons { get; set; }
}