Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't Get EF4 Eager Loading of Subclassed Entities to Work
    primarykey
    data
    text
    <p>I have an abstract Content entity in my EF4 model with a concrete subclass, MultipleChoiceItem. There is a related table in the case of MultipleChoiceItem accessed by a Navigation property on the MultipleChoiceItem entity called Options. I would like to eager-load the Options result because if you're getting a MultipleChoiceItem, you always want the Options. However, I can't seem to get this to work. Here is what I've bascially done:</p> <ul> <li><p>The MultipleChoiceItem is a subclass, therefore it didn't get metadata created by default. So, I created a metadata class for it that looks sort of like this: </p> <pre><code>[MetadataTypeAttribute(typeof(MultipleChoiceItem.ContentMetadata))] public partial class MultipleChoiceItem { internal sealed class MultipleChoiceItemMetadata { ... other stuff ... [Include] public EntityCollection&lt;McOption&gt; Options { get; set; } ... other stuff ... } </code></pre></li> <li><p>I then created a new query in the ContentService that looks like this: </p> <pre><code>public IQueryable&lt;Content&gt; GetMultipleChoiceItems() { return this.ObjectContext.Contents.OfType&lt;MultipleChoiceItem&gt;() .Include("Options"); } </code></pre></li> </ul> <p>In a unit test, I'm calling that like this:</p> <pre><code> context = new ContentContext(); var loadOperation = context.Load(context.GetMultipleChoiceItemsQuery()); loadOperation.Completed += new EventHandler(CompletedHandler); </code></pre> <p>Once I get into the CompletedHandler, the following code doesn't seem to have the Options property loaded--in fact, Options.Count == 0 when it should be 4 (verified by checking the underlying data store).</p> <pre><code> MultipleChoiceItem mci = context.Contents.First(c =&gt; c.ContentId == mciId) as MultipleChoiceItem; </code></pre> <p>Can anyone tell me what I'm doing wrong? I've tried to follow the models I've seen posted and am apparently missing something...</p> <p>Thanks!</p>
    singulars
    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.
    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