Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This query should work:</p> <pre><code>var query = from row in table let ignore = row.Label == "Total" orderby ignore, row.Value descending select row.Label; //and corresponding lambda version var lquery = table.OrderBy(row =&gt; row.Label == "Total") .ThenByDescending(row =&gt; row.Value) .Select(row =&gt; row.Label); </code></pre> <p>Note: it isn't entirely necessary to create a <code>ignore</code> variable, it could be placed directly in the orderby clause. This way, it makes it more readable.</p> <p>Not sure what you are asking in your second question.</p> <hr> <p><strong>edit:</strong><br> In response to your comment, it would depend on how you wanted the sorting to work, at least written like this. This works well if there is only one row in the table that you want to completely ignore. Not so much if you had more than one. The problem being that among the "ignored" rows, will be sorted by the original sorting as well (in this case, by <code>Value</code>). A naive way to add another row is to add to the ignore condition.</p> <pre><code>var query = from row in table let ignore = row.Label == "Total" || row.Label == "Cost" orderby ignore, row.Value descending select row.Label; </code></pre> <p>To have a specific ordering among the "ignored" rows, it would require a somewhat more complex query:</p> <pre><code>var query = from row in table let ignore = row.Label == "Total" || row.Label == "Cost" let ignoreorder = row.Label == "Cost" ? 1 : 0 orderby ignore, ignoreorder, row.Value descending select row.Label; //and corresponding lambda version var lquery = table.OrderBy(row =&gt; row.Label == "Total" || row.Label == "Cost") .ThenBy(row =&gt; row.Label == "Cost" ? 1 : 0) .ThenByDescending(row =&gt; row.Value) .Select(row =&gt; row.Label); </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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