Note that there are some explanatory texts on larger screens.

plurals
  1. POComparer is not getting called when Sorting an IList
    primarykey
    data
    text
    <p>I have a really annoying error whereby my comparer.Compare(x, y) is not getting called. I have an IList that is returning a bunch of entities from the database and then I'm sorting a list of entities inside each entity returned from the database.</p> <p>ie: in this example each household has many accounts, and i want to sort the sub-list by properties on the accounts entities.</p> <p>My calling logic is as follow:</p> <pre><code> List&lt;Household&gt; households = query.ToList(); households.Sort(new HouseholdComparer()); return households; </code></pre> <p>and my comparer looks like this:</p> <pre><code>public class HouseholdComparer : IComparer&lt;Household&gt; { public int Compare(Household x, Household y) { foreach (Account xAccount in x.Accounts) { foreach (Account yAccount in y.Accounts) { if (xAccount.StartDate == yAccount.StartDate) { if ((xAccount.RevenueT12.HasValue &amp;&amp; yAccount.RevenueT12.HasValue) &amp;&amp; (xAccount.RevenueT12.Value == yAccount.RevenueT12.Value)) { if ((xAccount.AUAAnnual.HasValue &amp;&amp; yAccount.AUAAnnual.HasValue) &amp;&amp; (xAccount.AUAAnnual.Value == yAccount.AUAAnnual.Value)) return 0; // all same whatever result if (!xAccount.AUAAnnual.HasValue || !yAccount.AUAAnnual.HasValue) return 0; if (xAccount.AUAAnnual.Value &gt; yAccount.AUAAnnual.Value) return 1; if (xAccount.AUAAnnual.Value &lt; yAccount.AUAAnnual.Value) return -1; } else { if (!xAccount.RevenueT12.HasValue || !yAccount.RevenueT12.HasValue) return 0; if (xAccount.RevenueT12.Value &gt; yAccount.RevenueT12.Value) return 1; if (xAccount.RevenueT12.Value &lt; yAccount.RevenueT12.Value) return -1; } } else { if (x.StartDate &gt; y.StartDate) return 1; if (x.StartDate &lt; y.StartDate) return -1; } } } return 0; // it shouldn't get here } </code></pre> <p>When I run the debugger I get a hit in the constructor but nothing in the compare method, can anyone help?????</p>
    singulars
    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.
 

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