EF CTP4 lazy loading not playing ball

旧时模样 提交于 2019-12-24 07:03:19

问题


I'm using the CTP4 code first EF framework, but I'm having problems getting lazy loading to work. Reading up on it, it should be simple, but it's just not

public class Folder
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int? ParentFolderId { get; set; }

    public virtual IList<Folder> ChildFolders { get; set; }
}

In the model configuration:

HasMany(f => f.ChildFolders).WithOptional().HasConstraint((child, folder) => child.ParentFolderId == folder.Id);

However, when I do this:

Folder folder = context.Folders.SingleOrDefault(f => f.Id == 1);

folder.ChildPages is null....but it should be lazy loading it...


回答1:


I found the answer to this, actually: The empty constructor for "Folder" was marked internal, and although there were no hard failures, it seems this was enough to cause problems.




回答2:


Is your context based on DbContext or ObjectContext? If it is ObjectContext then you have to turn on lazy loading in ContextOptions.



来源:https://stackoverflow.com/questions/3881374/ef-ctp4-lazy-loading-not-playing-ball

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!