Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding subitems to a mvc model without needing to loop thru a list?
    primarykey
    data
    text
    <p>Using mvc 3 with EF 4.1 (with stored procedures). I have a list of issues and I need to include a list of comments to each issue. Not sure how if this can be done in one proc and one model without looping thru each issue model and adding comments. Here's what I have so far: (In short need a better approach)</p> <p>My procedure "SP_GetQuestionIssues":</p> <pre><code>CREATE PROC [dbo].[SP_GetQuestionIssues] (@ReviewID int) AS Select r.ReviewID, q.QuestionId, s.Title Step, q.QuestionText Question, r.AnswerValue Answer, IsIssue From dbo.Questions q Join dbo.Steps s on q.StepId = s.StepId Join dbo.QuestionFlagged qf on q.questionId = qf.questionId Join dbo.Responses r on q.questionId = r.QuestionID Where IsIssue=1 AND r.ReviewID = @ReviewID AND qf.ReviewID = @ReviewID Order by s.StepID, s.stepOrder, q.DisplayOrder </code></pre> <p>My model "QuestionIssue":</p> <pre><code>public class QuestionIssue { public int ReviewID { get; set; } public int QuestionId { get; set; } public string Step { get; set; } public string Question { get; set; } public string Answer { get; set; } public bool IsIssue { get; set; } public virtual IEnumerable&lt;Comment&gt; Comments { get; set; } } </code></pre> <p>My model "Comment":</p> <pre><code>public class Comment { public int CommentId { get; set; } public int ReviewId { get; set; } public Nullable&lt;int&gt; QuestionId { get; set; } public string Reviewer { get; set; } public string CommentText { get; set; } public bool IsMemo { get; set; } } </code></pre> <p>My action:</p> <pre><code>SqlParameter param = new SqlParameter("@ReviewID", Id); var issues = db.Database.SqlQuery&lt;QuestionIssue&gt;("SP_GetQuestionIssues @ReviewID", param).ToList(); </code></pre> <p>Need a better approach than this (psuedo code):</p> <pre><code> foreach(var issue in issues) { var comments = somefunction.getcomments(issue.reviewId, issue.questionId) issue.Comments.add(comment) } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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