Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC .Net view nested list of models
    primarykey
    data
    text
    <p>I have an abstract class with 3 other classes that inherit from this class:-</p> <pre><code>public abstract class AbstractTask { [Key] public int ID {get; set;} [DisplayName("Featured Task")] public bool Featured { get; set; } // various other properties } public class HighLevelTask : AbstractTask { [DisplayName("Workstream Description")] public String Workstream { get; set; } public virtual ICollection&lt;MidLevelTask&gt; MidLevelTasks { get; set; } } public class MediumLevelTask : AbstractTask { public int HighLevelTaskID { get; set; } public virtual ICollection&lt;DetailLevelTask&gt; DetailLevelTasks { get; set; } } public class DetailLevelTask : AbstractTask { public int MidLevelTaskID { get; set; } } </code></pre> <p>So a High Level task can contain any number of Mid Level tasks and a Mid level task can contain any number of Detail tasks. Tasks at any level can be set as 'Featured' by the property inherited from the abstract class.</p> <p>In a HTML view I want to present a nested list of the 'featured' tasks. So I am thinking in a Controller action something like this to collect all the featured tasks but am at a mental block on the best way to present this.</p> <pre><code> var qryHighLevelTasks = from t in context.HighLevelTasks where t.Featured == true select t; var rsHighLevelTasks = qryHighLevelTasks.ToList(); foreach(var highLevelTask in rsHighLevelTasks) { // get all mid level featured tasks related to this high level task var qryMidTasks = from midLevelTasks in context.MidLevelTasks where midLevelTasks.Featured == true &amp;&amp; midLevelTasks.HighLevelTaskID == highLevelTask.ID select midLevelTasks; var rsMidLevelTasks = qryMidTasks.ToList(); foreach (var midLevelTask in rsMidLevelTasks) { // get all detail level featured tasks related to this mid level task var qryDetailTasks = from detailLevelTasks in context.DetailLevelTasks where detailLevelTasks.Featured == true &amp;&amp; detailLevelTasks.MidLevelTaskID == midLevelTask.ID select detailLevelTasks; var rsDetailLevelTasks = qryDetailTasks.ToList(); } } </code></pre> <p>Perhaps I should have a composite model to represent the featured tasks? Or is there a better way? Any recommendations?</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.
 

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