<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:37:00 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-492] LINQ - OrderBy after Select Doesn&apos;t Work</title>
                <link>https://jira.mongodb.org/browse/CSHARP-492</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;The following type of query throws an ArgumentNull exception in BsonDocument.cs Add method for parameter string name (line 624):&lt;/p&gt;

&lt;p&gt;.Where().Select(x =&amp;gt; x.Name).OrderBy(x =&amp;gt; x).ToArray()&lt;/p&gt;</description>
                <environment></environment>
        <key id="41147">CSHARP-492</key>
            <summary>LINQ - OrderBy after Select Doesn&apos;t Work</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</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="2">Won&apos;t Fix</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="zaidmasud">Zaid Masud</reporter>
                        <labels>
                            <label>C#</label>
                            <label>LINQ</label>
                            <label>linq,query</label>
                    </labels>
                <created>Wed, 13 Jun 2012 15:47:53 +0000</created>
                <updated>Thu, 20 Mar 2014 16:39:09 +0000</updated>
                            <resolved>Mon, 18 Jun 2012 20:31:04 +0000</resolved>
                                    <version>1.4.2</version>
                                                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="134098" author="craiggwilson" created="Mon, 18 Jun 2012 20:31:04 +0000"  >&lt;p&gt;Thanks for reporting Zaid.  Because we will not be supporting this for standard queries, I&apos;m going to close this report.&lt;/p&gt;</comment>
                            <comment id="131876" author="zaidmasud" created="Wed, 13 Jun 2012 16:24:07 +0000"  >&lt;p&gt;Makes sense... thanks for the responsiveness &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</comment>
                            <comment id="131871" author="rstam" created="Wed, 13 Jun 2012 16:21:59 +0000"  >&lt;p&gt;Either way would work.&lt;/p&gt;

&lt;p&gt;The difference is that ToList() and ToArray() cause the query to be evaluated immediately where AsEnumerable preserves the delayed execution behavior of LINQ queries.&lt;/p&gt;</comment>
                            <comment id="131869" author="zaidmasud" created="Wed, 13 Jun 2012 16:18:14 +0000"  >
&lt;p&gt;Fair enough.&lt;/p&gt;

&lt;p&gt;Although .ToList() or .ToArray() are a more standard use than AsEnumerable() to say you want the rest of the query to be executed on client side. See &lt;a href=&quot;http://stackoverflow.com/questions/3389855/am-i-misunderstanding-linq-to-sql-asenumerable&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://stackoverflow.com/questions/3389855/am-i-misunderstanding-linq-to-sql-asenumerable&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="131857" author="rstam" created="Wed, 13 Jun 2012 16:07:09 +0000"  >&lt;p&gt;I believe the standard LINQ way to say you want the rest of the LINQ query to be executed at the client is to stick a call to AsEnumerable() in the chain at the point where you want to transition from server side execution to client side execution:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var query = collection.AsQueryable().Select(c =&amp;gt; c.Name).AsEnumerable().OrderBy(n =&amp;gt; n);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;</comment>
                            <comment id="131851" author="zaidmasud" created="Wed, 13 Jun 2012 16:02:11 +0000"  >&lt;p&gt;Great, yes sorry I suppose the real issue here is only the error message and I was able to figure out the solution pretty easily.&lt;/p&gt;

&lt;p&gt;As a side note I suppose there could be an argument that the OrderBy after a select should effectively be an &quot;in-memory&quot; sort as opposed to a Mongo server sort.&lt;/p&gt;</comment>
                            <comment id="131845" author="rstam" created="Wed, 13 Jun 2012 15:57:08 +0000"  >&lt;p&gt;We don&apos;t support OrderBy after Select (because the OrderBy clause has to be expressed in terms of the original document type of the collection to be mapped to an order by clause in the MongoDB wire protocol).&lt;/p&gt;

&lt;p&gt;You can rewrite the query this way:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var query = collection.AsQueryable&amp;lt;X&amp;gt;().OrderBy(x =&amp;gt; x.Name).Select(x =&amp;gt; x.Name);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;I&apos;m leaving the JIRA ticket open nonetheless because the error message you are getting is not the appropriate response. We will improve the error message.&lt;/p&gt;</comment>
                            <comment id="131842" author="zaidmasud" created="Wed, 13 Jun 2012 15:55:01 +0000"  >&lt;p&gt;System.ArgumentNullException was unhandled by user code&lt;br/&gt;
  Message=Value cannot be null.&lt;br/&gt;
Parameter name: name&lt;br/&gt;
  Source=MongoDB.Bson&lt;br/&gt;
  ParamName=name&lt;br/&gt;
  StackTrace:&lt;br/&gt;
       at MongoDB.Bson.BsonDocument.Add(String name, BsonValue value) in C:\mongodb-mongo-csharp-driver-be03282\Bson\ObjectModel\BsonDocument.cs:line 626&lt;br/&gt;
       at MongoDB.Driver.Linq.SelectQuery.Execute() in C:\mongodb-mongo-csharp-driver-be03282\Driver\Linq\Translators\SelectQuery.cs:line 150&lt;br/&gt;
       at MongoDB.Driver.Linq.MongoQueryProvider.Execute(Expression expression) in C:\mongodb-mongo-csharp-driver-be03282\Driver\Linq\MongoQueryProvider.cs:line 146&lt;br/&gt;
       at MongoDB.Driver.Linq.MongoQueryable`1.GetEnumerator() in C:\mongodb-mongo-csharp-driver-be03282\Driver\Linq\MongoQueryable.cs:line 81&lt;br/&gt;
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)&lt;br/&gt;
       at System.Linq.Enumerable.ToList&lt;span class=&quot;error&quot;&gt;&amp;#91;TSource&amp;#93;&lt;/span&gt;(IEnumerable`1 source)&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </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|hrh7fr:</customfieldvalue>

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