简体   繁体   English

EF7代理集合未生成

[英]EF7 Proxy Collections Not Generating

I'm trying ASP.NET vNext / Entity Framework 7. 我正在尝试ASP.NET vNext /实体框架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. 如果我有2个类:A和B,其中一个A连接到许多“ B”,则实体框架不会生成任何代理集合或代理类。 Thus, when trying to access the collection property, it is always empty unless I add to the collection manually. 因此,当尝试访问collection属性时,除非我手动添加到collection中,否则它始终为空。 How does one implement lazy (or even eagerly) loaded collections in EF7? 如何在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. EF 7最初发布时不支持延迟加载

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. 需要明确的是,这并不是说我们打算从EF7中删除对延迟加载的支持,只是一些应用程序可以在实施延迟加载之前开始利用EF7的优势。

Though I have not yet migrated to EF 7, you should be able to eagerly load your object graph, eg 虽然我还没有迁移到EF 7,但是您应该能够急切地加载对象图,例如

using System.Data.Entity;

...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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