<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:38:01 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CSHARP-852] System.ArgumentOutOfRangeException when attempting to use custom IComparer with LINQ OrderBy</title>
                <link>https://jira.mongodb.org/browse/CSHARP-852</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Hi, &lt;/p&gt;

&lt;p&gt;I&apos;ve been getting an System.ArgumentOutOfRangeException when i attempt to use a custom IComparer with the OrderBy LINQ expression.&lt;/p&gt;

&lt;p&gt;var results = collection.AsQueryable&amp;lt;TestClass&amp;gt;().OrderBy( m =&amp;gt; m.Id, new NaturalSortComparer&amp;lt;string&amp;gt;() ).ToList();&lt;/p&gt;

&lt;p&gt;I&apos;ve attached a program which demonstrates the problem.&lt;/p&gt;

&lt;p&gt;I do have a workaround for this by putting ToList before the OrderBy call but this is not ideal.&lt;/p&gt;

&lt;p&gt;Any suggestions?&lt;/p&gt;</description>
                <environment>windows 7 x64</environment>
        <key id="95755">CSHARP-852</key>
            <summary>System.ArgumentOutOfRangeException when attempting to use custom IComparer with LINQ OrderBy</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="jon.swain@autocab.com">Jon Swain</reporter>
                        <labels>
                            <label>question</label>
                    </labels>
                <created>Fri, 25 Oct 2013 15:30:05 +0000</created>
                <updated>Fri, 5 Apr 2019 13:58:13 +0000</updated>
                            <resolved>Fri, 25 Oct 2013 15:47:07 +0000</resolved>
                                    <version>1.8.3</version>
                                                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="446728" author="jon.swain@autocab.com" created="Fri, 25 Oct 2013 15:50:06 +0000"  >&lt;p&gt;Some of our Ids are alpha numeric so we can&apos;t store as integers.&lt;/p&gt;

&lt;p&gt;My data sets are not that large so i can handle it client side.&lt;/p&gt;

&lt;p&gt;Cheers for your help&lt;/p&gt;</comment>
                            <comment id="446722" author="craiggwilson" created="Fri, 25 Oct 2013 15:47:07 +0000"  >&lt;p&gt;Yeah, that&apos;s just kinda how it is.  LINQ is a big leaky abstraction so it&apos;s gonna let you do a lot of stuff client-side that isn&apos;t always possible server side.  You&apos;ll get runtime exceptions when this happens.&lt;/p&gt;

&lt;p&gt;Keep in mind that a client-side sort is going to be done in memory, so if you have lots of data, it could be slow.  Any reason not to store these as integers instead of strings?&lt;/p&gt;</comment>
                            <comment id="446717" author="jon.swain@autocab.com" created="Fri, 25 Oct 2013 15:44:54 +0000"  >&lt;p&gt;OK, i didn&apos;t realize this. &lt;/p&gt;

&lt;p&gt;The built in sort is ok but as they are string representations of numbers i don&apos;t get a natural sort. &lt;/p&gt;

&lt;p&gt;i.e. i get the following&lt;/p&gt;

&lt;p&gt;1&lt;br/&gt;
10&lt;br/&gt;
2&lt;br/&gt;
3&lt;br/&gt;
30&lt;br/&gt;
4&lt;/p&gt;

&lt;p&gt;but the NaturalSortComparer sort like the following&lt;/p&gt;

&lt;p&gt;1&lt;br/&gt;
2&lt;br/&gt;
3&lt;br/&gt;
4&lt;br/&gt;
10&lt;br/&gt;
30&lt;/p&gt;

&lt;p&gt;Its not a big issue i can workaround it or do the sorting on the client side.&lt;/p&gt;

&lt;p&gt;Cheers&lt;/p&gt;</comment>
                            <comment id="446706" author="craiggwilson" created="Fri, 25 Oct 2013 15:33:12 +0000"  >&lt;p&gt;You can&apos;t use a custom comparer for LINQ.  To do this would mean we&apos;d have to interpret the code in your custom comparer and then send that to MongoDB and it would need to apply that custom logic there.  All of this is impossible.&lt;/p&gt;

&lt;p&gt;Unfortunately, the only way to accomplish this would be to do the sort client-side.  Are you sure the built-in MongoDB sort is not accurate?  What does your NaturalSortComparer do differently?&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="32996" name="Program.cs" size="3372" author="jon.swain@autocab.com" created="Fri, 25 Oct 2013 15:30:05 +0000"/>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrts7z:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>87701</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>