简体   繁体   中英

EF7 Proxy Collections Not Generating

I'm trying ASP.NET vNext / Entity Framework 7.

If I have 2 classes: A and B, where one A connects to many "B's," Entity Framework does not generate any proxy collection or proxy class. Thus, when trying to access the collection property, it is always empty unless I add to the collection manually. How does one implement lazy (or even eagerly) loaded collections in EF7?

public class A {
    public Guid UniqueId {get;set;}
    private ICollection<B> _backing;
    public virtual ICollection<B> OneToManyRelationship { 
      get { return _backing ?? (_backing = new Collection<B>()); }
      set { _backing = value; } }
}

public class B {
    public A Owner {get;set;}
    public string UniqueIdentifier {get;set;}
    public int SomeImportantData {get;set;}
}

EF 7 does not support lazy loading upon initial release.

An example of this is lazy loading support, we know this is a critical feature for a number of developers, but at the same time there are many applications that can be developed without this feature. Rather than making everyone wait until it is implemented, we will ship when we have a stable code base and are confident that we have the correct factoring in our core components. To be clear, it's not that we are planning to remove lazy loading support from EF7, just that some apps can start taking advantage of the benefits of EF7 before lazy loading is implemented.

Though I have not yet migrated to EF 7, you should be able to eagerly load your object graph, eg

using System.Data.Entity;

...

var query = ctx.A.Include(a => a.OneToManyRelationship);

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