【发布时间】:2015-11-18 21:21:09
【问题描述】:
我有一个产品实体和一个子产品实体:
public class Product
{
public virtual ICollection<ProdAttribute> Attributes { get; set; }
public virtual ICollection<ChildProduct> Children { get; set; }
public string ItemID { get; set; }
public string ItemName { get; set; }
}
public class ChildProduct
{
public virtual ICollection<ProdAttribute> Attributes { get; set; }
public int DisplayOrder { get; set; }
public string ItemID { get; set; }
public string ItemName { get; set; }
public virtual Product Parent { get; set; }
public string ParentItemID { get; set; }
public string Size { get; set; }
}
在我的上下文中,我只是使用以下内容获取产品及其子项:
return _axaptaContext.Products
.Include(x => x.Children)
.Include(x => x.Attributes);
现在我希望孩子也包含属性,所以我尝试使用
return _axaptaContext.Products
.Include(x => x.Children)
.Include("Children.Attributes")
.Include(x => x.Attributes);
但这会导致查询超时。当我尝试调用时,如何延迟加载孩子的属性:
product.Children.Attribtutes
它只是返回空值。我发现的关于延迟加载的所有内容都表明,如果我将属性标记为虚拟属性,则它们应该是延迟加载的
【问题讨论】:
标签: c# entity-framework lazy-loading