Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This seems to be a limitation in the current version of Entity Framework (1.0) Have a look at <a href="https://stackoverflow.com/questions/944332/entity-framework-inheritance-and-include">this related SO question</a>.</p> <p>In your case including the related <strong>UserCreated</strong> and <strong>UserEdited</strong> properties in the projection is the right solution. However if you also want to populate the <strong>Image</strong> property on the <strong>UserSpecial</strong> object, you must be sure to include that as well:</p> <pre><code>var results = from articleSpecial in ctx.ArticleBase.OfType&lt;ArticleSpecial&gt;() select new { articleSpecial, articleSpecial.UserCreated, ((UserSpecial)articleSpecial.UserCreated).Image, articleSpecial.UserEdited, ((UserSpecial)articleSpecial.UserEdited).Image }; </code></pre> <p>Of course this query builds on the assumption that <strong>all ArticleSpecial entities always refer to a UserSpecial entity</strong>, otherwise the casting will fail.<br/> If this assumption isn't always true, you could express the same query using the LINQ extension methods and a multi-line lambda function to perform a safe casting:</p> <pre><code>var results = ctx.ArticleBase .OfType&lt;ArticleSpecial&gt;() .AsEnumerable() .Select(a =&gt; { var userCreated = a.UserCreated as UserSpecial; if (userCreated != null) { var image = userCreated.Image; } var userEdited = a.UserEdited as UserSpecial; if (userEdited != null) { var image = userEdited.Image; } return a; }); </code></pre> <p>In the latter example, you also do not need to include <strong>UserSpecial</strong> and <strong>Image</strong> entities in the results. Instead you just need to access the navigation properties on the <strong>ArticleSpecial</strong> entities during the projection phase in order to force Entity Framework to eager load the related objects. </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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