Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity Framework POCO T4 sometimes creates an EntityCollection and sometimes creates a FixUpCollection
    primarykey
    data
    text
    <p>I've run into a strange issue with the Entity Framework POCOs created by the POCO T4 templates - for some objects their collection properties are created as an <code>EntityCollection</code>, and for others they're created as a <code>FixUpCollection</code>.</p> <p>I'm finding this with three classes which model a product hierarchy; <code>ProductGroup</code>, <code>Platform</code> and <code>Product</code>. Each <code>ProductGroup</code> has a collection of <code>Platform</code>s, and each <code>Platform</code> has a collection of <code>Product</code>s. All the relationships are bi-directional. The collection getters and setters are exactly the same for each class because they're generated by the T4 template, so they all look (e.g.) like this:</p> <pre><code>public virtual ICollection&lt;Platform&gt; Platforms { get { if (_platforms == null) { var newCollection = new FixupCollection&lt;Platform&gt;(); newCollection.CollectionChanged += FixupPlatforms; _platforms = newCollection; } return _platforms; } set { ... } } </code></pre> <p>The funny thing is, <em>all</em> the collections on <code>Product</code> and <code>Platform</code> are created as <code>EntityCollection</code>s, and <em>all</em> the collections on <code>ProductGroup</code> are created as <code>FixUpCollection</code>s. i.e. when the code first enters the getter of (e.g.) <code>Platform.Products</code>, the <code>_products</code> field is already populated with an <code>EntityCollection</code>, but when it first enters the getter shown above, <code>_platforms</code> is null and a <code>FixupCollection</code> is created and subsequently populated. Lazy-loading is working in both cases, it's just working in two different ways.</p> <p>The <code>Entities</code> object has lazy-loading and proxy creation enabled. <code>Product</code>, <code>Platform</code> and <code>CoreProduct</code> objects are all dynamic EF proxies in the <code>Entity.DynamicProxies</code> namespace. I've tried eager loading the <code>Platform</code> and <code>ProductGroup</code>, which made no difference. I can't see any difference in how the classes are set up in the model viewer.</p> <p>This is causing me a headache because one of the collections on <code>ProductGroup</code> contains thousands of objects, and I want to query that collection. As far as I know (please do correct me if I'm wrong) I can't query a <code>FixUpCollection</code> without loading all the objects into memory, which is not the case for an <code>EntityCollection</code> because I can use <a href="http://msdn.microsoft.com/en-us/library/bb896438.aspx" rel="nofollow"><code>CreateSourceQuery()</code></a>. Has anyone seen this behaviour before? Is there some setting I'm missing somewhere? Any pointers or help would be much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload