Note that there are some explanatory texts on larger screens.

plurals
  1. POInclude Derived Models Related Class
    text
    copied!<p>Here's the Lambda expression I am using to try and include the <code>User</code> table, which throws an error.</p> <pre><code>ICollection&lt;Activity&gt; activity = db.Activities .Include(i =&gt; i.Project.ProjectDoc.OfType&lt;Cover&gt;().Select(v =&gt; v.User)) .Where(u =&gt; u.UserID == WebSecurity.CurrentUserId) .OrderByDescending(d =&gt; d.DateCreated).ToList(); </code></pre> <p>The include statement gives this error</p> <blockquote> <p>The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties.</p> </blockquote> <p>The model in question</p> <pre><code>public abstract class ProjectDoc { public int ProjectDocID { get; set; } public int ProjectID { get; set; } public string DocTitle { get; set; } public string Status { get; set; } public string Access { get; set; } public DateTime DateCreated { get; set; } public virtual ProjectDocAccess ProjectDocAccess { get; set; } public virtual Project Project { get; set; } public virtual ICollection&lt;Comment&gt; Comment { get; set; } public ICollection&lt;ProjectDocVote&gt; ProjectDocVote { get; set; } } public class Segment : ProjectDoc { public string Content { get; set; } } public class Cover : ProjectDoc { public string CoverURL { get; set; } public int UserID { get; set; } public User User { get; set; } } </code></pre> <p>How do I include the <code>User</code> table for the <code>ProjectDoc</code> of type <code>Cover</code>?</p> <p><strong>UPDATE</strong>: Per the answer. I updated the model for <code>Cover</code> to looks like this and removed the include that I said was causing the error. I can now get the data:</p> <pre><code>public class Cover : ProjectDoc { public string CoverURL { get; set; } public int UserID { get; set; } public virtual User User { get; set; } } </code></pre>
 

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