Lazy,Eager和Explicit加载在Entity Framework 5中不起作用

时间:2015-12-07 04:40:37

标签: entity-framework

系类:

public partial class Department
{
    public Department()
    {
        this.Courses = new HashSet<Course>();
    }

    public int DepartmentID { get; set; }
    public string Name { get; set; }
    public virtual ICollection<Course> Courses { get; set; }

}

课程类:

public partial class Course
{
     public Course()
     {
         this.Enrollments = new HashSet<Enrollment>();
         this.People = new HashSet<Person>();
     }

     public int CourseID { get; set; }
     public string Title { get; set; }
     public int DepartmentID { get; set; }
     public virtual Department Department { get; set; }

}

上下文:

延迟加载启用如下。

universityDBContext.Configuration.LazyLoadingEnabled = true;
universityDBContext.Configuration.ProxyCreationEnabled = true;

延迟加载在Entity Framework 5中无效。请帮助

2 个答案:

答案 0 :(得分:0)

public partial class Department
{
    public Department()
    {
        this.Courses = new HashSet<Course>();
        this.Students = new HashSet<Student>();
    }

    public int DepartmentID { get; set; }
    public string Name { get; set; }
    public decimal Budget { get; set; }
    public System.DateTime StartDate { get; set; }
    public Nullable<int> InstructorID { get; set; }
    public byte[] RowVersion { get; set; }

    public virtual ICollection<Course> Courses { get; set; }
    public virtual ICollection<Student> Students { get; set; }
    public virtual Person Person { get; set; }
}

答案 1 :(得分:0)

public partial class Course
{
    public Course()
    {
        this.Enrollments = new HashSet<Enrollment>();
        this.People = new HashSet<Person>();
    }

    public int CourseID { get; set; }
    public string Title { get; set; }
    public int Credits { get; set; }
    public int DepartmentID { get; set; }
    public byte[] rowversion { get; set; }

    [ForeignKey("Department")]
    public virtual Department Department { get; set; }
    public virtual ICollection<Enrollment> Enrollments { get; set; }
    public virtual ICollection<Person> People { get; set; }
}