EF CTP4懒加载不玩球 [英] EF CTP4 lazy loading not playing ball

查看:120
本文介绍了EF CTP4懒加载不玩球的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CTP4代码第一个EF框架,但我有懒惰加载工作的问题。阅读它,它应该很简单,但它只是不是

  public class文件夹
{
public int Id {get;组; }
public string Name {get;组; }
public int? ParentFolderId {get;组; }

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

在模型配置中:

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

但是,当我这样做:

 文件夹文件夹= context.Folders.SingleOrDefault(f => f.Id == 1); 

folder.ChildPages是null ....但它应该是懒惰加载它...


解决方案

我发现这个答案实际上是:文件夹的空构造函数被标记为内部,虽然没有硬故障这似乎足以引起问题。


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...

解决方案

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.

这篇关于EF CTP4懒加载不玩球的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆