为什么Entity Framework使用代理进行延迟加载?

时间:2016-05-18 23:08:08

标签: c# entity-framework lazy-loading lazyload

我有点困惑,我想知道为什么EF使用代理来实现延迟加载?

我的意思是为什么要动态创建课程而不是像这样的

public partial class Product
{
    public int Id { get; set; }
    public string PName { get; set; }
    public Nullable<int> Cat_Id { get; set; }
    private category;
    public Category Category { get{this.category = getCat(this.Id); return this.category;} set{this.category= value;} }
}

getCat(int Id)
{
  if(Id != 0)
  {   
      //Write Code 
  }
}

0 个答案:

没有答案