当实体类是内部的时,可以强制实体框架到Lazy加载集合吗?所有代码都是首先用代码编写的,并且是流畅的API。我有这样的情况:
internal class Order
{
public int Id { get; set; }
public ICollection<Operation> Operations { get; set; }
}
internal class Operation
{
public int Id { get; set; }
public int OrderId { get; set; }
public Order Order { get; set; }
}
internal MyContext : DbContext
{
internal DbSet<Order> Orders { get; set; }
internal DbSet<Operation> Operations { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Operation>().HasRequired(x => x.Order)
.WithMany(x => x.Operations)
.HasForeignKey(x=>x.OrderId);
}
}
我无法弄清楚为什么实体框架不会延迟加载Operations Collection。我在上下文中加载了lazy。有可能管理这个吗?