Note that there are some explanatory texts on larger screens.

plurals
  1. POLinq order by isn't ordering anything
    text
    copied!<pre><code>// Query all records var q = dc.tblHelpCentreQuestions.Where(question =&gt; question.userID == UserID).Where(question =&gt; question.awaitingUserResponse == true || question.awaitingSupportResponse == true). OrderBy(s =&gt; s.awaitingUserResponse).ThenBy(s =&gt; s.dateSubmitted). GroupJoin( dc.tblHelpCentreReplies, question =&gt; question.ID, replies =&gt; replies.ticketID, (question, replies) =&gt; new { Question = question, RepliesCount = replies.Count() } ); </code></pre> <p>No matter where I put the order by query, it seems to just be ordering them randomly.</p> <h2>Edit: same results with order at end:</h2> <pre><code>// Query all records var q = dc.tblHelpCentreQuestions.Where(question =&gt; question.userID == UserID).Where(question =&gt; question.awaitingUserResponse == true || question.awaitingSupportResponse == true). GroupJoin( dc.tblHelpCentreReplies, question =&gt; question.ID, replies =&gt; replies.ticketID, (question, replies) =&gt; new { Question = question, RepliesCount = replies.Count() } ).OrderBy(s =&gt; s.Question.awaitingUserResponse).ThenBy(s =&gt; s.Question.dateSubmitted); </code></pre> <h2>Edit: Generated SQL</h2> <pre><code>exec sp_executesql N'SELECT [t2].[ID], [t2].[catID], [t2].[subject], [t2].[question], [t2].[userID], [t2].[dateSubmitted], [t2].[isUrgent], [t2].[emailMe], [t2].[awaitingSupportResponse], [t2].[awaitingUserResponse], [t2].[lastReply], [t2].[stopWatchTotalMins], [t2].[isStopWatchOn], [t2].[stopWatchStart], [t2].[priorityLevel], [t2].[value] AS [RepliesCount] FROM ( SELECT [t0].[ID], [t0].[catID], [t0].[subject], [t0].[question], [t0].[userID], [t0].[dateSubmitted], [t0].[isUrgent], [t0].[emailMe], [t0].[awaitingSupportResponse], [t0].[awaitingUserResponse], [t0].[lastReply], [t0].[stopWatchTotalMins], [t0].[isStopWatchOn], [t0].[stopWatchStart], [t0].[priorityLevel], ( SELECT COUNT(*) FROM [dbo].[tblHelpCentreReplies] AS [t1] WHERE ([t0].[ID]) = [t1].[ticketID] ) AS [value] FROM [dbo].[tblHelpCentreQuestions] AS [t0] ) AS [t2] WHERE (([t2].[awaitingUserResponse] = @p0) OR ([t2].[awaitingSupportResponse] = @p1)) AND ([t2].[userID] = @p2) ORDER BY [t2].[awaitingUserResponse], [t2].[dateSubmitted]', N'@p0 int,@p1 int,@p2 int', @p0 = 1, @p1 = 1, @p2 = 81 </code></pre> <p>I've run the code through the database and it returns the results correctly, so it must be something else which is strange because the code is so simple, never mind though, thanks all for your help, I've learnt a lot of new things with this problem!</p>
 

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