EF代码首先不加载我的子对象集合

时间:2012-03-06 20:51:56

标签: entity-framework-4 code-first

我有两个对象:

public class Program 
{       
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]       
    public long Id { get; set; }       
    public string Name { get; set; }    
    public virtual ICollection<VideoFile> Files { get; set; }
}

public class VideoFile
    {   
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]       
        public long Id { get; set; }   
        [Required]
        public string Path { get; set; }
        [Required]
        public virtual Program Program { get; set; }       
    }

这两个表是在数据库中正确创建的,当我保存程序时它也插入了他的文件子项,但是当我试图获取程序时,文件集合为空,我有LazyLoad启用,默认情况下实体框架返回当一个子集合为空时,为什么我有null?

0 个答案:

没有答案