简体   繁体   中英

When entity is internal, lazy loading does not work

It is possible to force entity framework to Lazy loading collection when entity class is internal? All code is written in code first and fluent API. I have situation like this:

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);
   }
}

And I can't figure out why entity framework doesn't lazy loading Operations Collection. I have lazy loading true in context. It is possible to manage this?

I'm afraid that is not possible, public classes is a requirement for EF to create proxy classes and to enable lazy loading. Take a look this msdn page for more info:

A custom data class must be declared with public access.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM