Note that there are some explanatory texts on larger screens.

plurals
  1. POLINQ query using TPH inheritance - get derived class ICollection count
    primarykey
    data
    text
    <p>I am trying to figure out how to get the count of ProjectSummaryVotes on a specific ProjectDoc.OfType. The query works but the ProjectSummaryVote attribute is null, which means I get a null value error. Is this doable? Should I abandon TPH inheritance if I need to do this? </p> <p>Model:</p> <pre><code>public class Project { public int ProjectID { get; set; } public virtual ICollection&lt;ProjectDoc&gt; ProjectDoc { get; set; } } 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 DateTime DateCreated { get; set; } public virtual Project Project { get; set; } public virtual ICollection&lt;Comment&gt; Comment { get; set; } } public class Summary : ProjectDoc { [DataType(DataType.MultilineText)] public string Text { get; set; } public ICollection&lt;ProjectSummaryVote&gt; ProjectSummaryVote { get; set; } } public class ProjectSummaryVote { public int ProjectSummaryVoteID { get; set; } public int ProjectDocID { get; set; } public bool Vote { get; set; } public virtual Summary Summary { get; set; } public virtual User User { get; set; } } </code></pre> <p>Query:</p> <pre><code> Project project = db.Projects .Include(i =&gt; i.User) .Include(i =&gt; i.ProjectDoc) .SingleOrDefault(x =&gt; x.ProjectID == id); </code></pre> <p>Attempt to get the count that throws an error.</p> <pre><code> var trueCount = Model.ProjectDoc.OfType&lt;Literrater.Models.Summary&gt;() .Where(s =&gt; s.Status == "Active") .SelectMany(v =&gt; v.ProjectSummaryVote.Where(s =&gt; s.Vote == true)) .Count(); </code></pre>
    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