【发布时间】:2011-04-30 06:43:17
【问题描述】:
我在 1:n 关系中有两个实体:类别和产品。
public class Category
{
public int CategoryID { get; set; }
public string CategoryName { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
public class Product
{
public int ProductID { get; set; }
public string ProductName { get; set; }
public virtual Product { get; set; }
}
public class context : DbContext
{
public DbSet<Category> Categories { get; set; }
public DbSet<Product> Products { get; set; }
}
我想通过 Eager loading 加载每个类别的产品。
context.Categories.Include(c=>c.Products)
但包含不加载任何导航属性。它只接受一个名为“path”的参数类型的字符串。
【问题讨论】:
标签: ef-code-first eager-loading