<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:48:26 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-4509] Support Convert calls to a base type in expression translators</title>
                <link>https://jira.mongodb.org/browse/CSHARP-4509</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;h4&gt;&lt;a name=&quot;Summary&quot;&gt;&lt;/a&gt;Summary&lt;/h4&gt;

&lt;p&gt;When migrating to LINQ provider v3, sorting no longer works in cases where the key selector expression has a compile time type of `System.Object` (but the appropriate runtime type).&lt;/p&gt;

&lt;p&gt;We discovered this when migrating to driver version 2.19.0, where LINQ3 is the new default. If we manually set the LINQ provider to v2, things go back to working as expected.&lt;/p&gt;
&lt;h4&gt;&lt;a name=&quot;HowtoReproduce&quot;&gt;&lt;/a&gt;How to Reproduce&lt;/h4&gt;

&lt;p&gt;See attached for a minimal console app that reproduces the behavior. Notable lines:&lt;/p&gt;

&lt;p&gt;```&lt;br/&gt;
Expression&amp;lt;Func&amp;lt;DbJob, object&amp;gt;&amp;gt; selector = sortOrder switch&lt;/p&gt;
{
&#160; &#160; JobSortColumn.JobNumber =&amp;gt; j =&amp;gt; j.JobNumber,
&#160; &#160; JobSortColumn.DriverName =&amp;gt; j =&amp;gt; j.DriverName,
}
&lt;p&gt;;&lt;/p&gt;

&lt;p&gt;jobsQueryable = jobsQueryable.OrderByDescending(selector);&lt;br/&gt;
var jobs = await jobsQueryable.ToListAsync(); // error if LINQ provider is v3&lt;br/&gt;
```&lt;/p&gt;

&lt;p&gt;The resulting exception if LINQ3 is enabled:&lt;/p&gt;

&lt;p&gt;```&lt;/p&gt;

&lt;p&gt;Unhandled exception. MongoDB.Driver.Linq.ExpressionNotSupportedException: Expression not supported: Convert(j.JobNumber, Object) because conversion to System.Object is not supported.&lt;br/&gt;
&#160; &#160;at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.ConvertExpressionToAggregationExpressionTranslator.Translate(TranslationContext context, UnaryExpression expression)&lt;br/&gt;
&#160; &#160;at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.UnaryExpressionToAggregationExpressionTranslator.Translate(TranslationContext context, UnaryExpression expression)&lt;br/&gt;
&#160; &#160;at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.ExpressionToAggregationExpressionTranslator.Translate(TranslationContext context, Expression expression)&lt;br/&gt;
&#160; &#160;at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.ExpressionToAggregationExpressionTranslator.TranslateLambdaBody(TranslationContext context, LambdaExpression lambdaExpression, IBsonSerializer parameterSerializer, Boolean asRoot)&lt;br/&gt;
&#160; &#160;at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.OrderByMethodToPipelineTranslator.Translate(TranslationContext context, MethodCallExpression expression)&lt;br/&gt;
&#160; &#160;at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.ExpressionToPipelineTranslator.Translate(TranslationContext context, Expression expression)&lt;br/&gt;
&#160; &#160;at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToExecutableQueryTranslators.ExpressionToExecutableQueryTranslator.Translate&lt;span class=&quot;error&quot;&gt;&amp;#91;TDocument,TOutput&amp;#93;&lt;/span&gt;(MongoQueryProvider`1 provider, Expression expression)&lt;br/&gt;
&#160; &#160;at MongoDB.Driver.Linq.Linq3Implementation.MongoQuery`2.ToCursorAsync(CancellationToken cancellationToken)&lt;br/&gt;
&#160; &#160;at MongoDB.Driver.IAsyncCursorSourceExtensions.ToListAsync&lt;span class=&quot;error&quot;&gt;&amp;#91;TDocument&amp;#93;&lt;/span&gt;(IAsyncCursorSource`1 source, CancellationToken cancellationToken)&lt;br/&gt;
&#160; &#160;at Program.&amp;lt;Main&amp;gt;$(String[] args) in /Users/mirek/RiderProjects/ConsoleApp1/ConsoleApp1/Program.cs:line 21&lt;br/&gt;
&#160; &#160;at Program.&amp;lt;Main&amp;gt;(String[] args)&lt;/p&gt;

&lt;p&gt;```&lt;/p&gt;</description>
                <environment></environment>
        <key id="2249106">CSHARP-4509</key>
            <summary>Support Convert calls to a base type in expression translators</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</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="13201">Fixed</resolution>
                                        <assignee username="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="mirek@rynly.com">Mirek Kukla</reporter>
                        <labels>
                            <label>LINQ3</label>
                    </labels>
                <created>Tue, 31 Jan 2023 23:32:10 +0000</created>
                <updated>Sat, 28 Oct 2023 11:46:58 +0000</updated>
                            <resolved>Thu, 16 Feb 2023 05:12:26 +0000</resolved>
                                                    <fixVersion>2.19.1</fixVersion>
                                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="5299663" author="xgen-internal-githook" created="Fri, 24 Mar 2023 18:59:59 +0000"  >&lt;p&gt;Author: &lt;/p&gt;
{&apos;name&apos;: &apos;rstam&apos;, &apos;email&apos;: &apos;robert@robertstam.org&apos;, &apos;username&apos;: &apos;rstam&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-4509&quot; title=&quot;Support Convert calls to a base type in expression translators&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-4509&quot;&gt;&lt;del&gt;CSHARP-4509&lt;/del&gt;&lt;/a&gt;: Support Convert calls to a base type in expression translators.&lt;br/&gt;
Branch: v2.19.x&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/24daa49a4addf66198901b529d15b7531bc88d7e&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/24daa49a4addf66198901b529d15b7531bc88d7e&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="5202926" author="xgen-internal-githook" created="Thu, 16 Feb 2023 05:11:52 +0000"  >&lt;p&gt;Author: &lt;/p&gt;
{&apos;name&apos;: &apos;rstam&apos;, &apos;email&apos;: &apos;robert@robertstam.org&apos;, &apos;username&apos;: &apos;rstam&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-4509&quot; title=&quot;Support Convert calls to a base type in expression translators&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-4509&quot;&gt;&lt;del&gt;CSHARP-4509&lt;/del&gt;&lt;/a&gt;: Support Convert calls to a base type in expression translators.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/2df43ecf335d3a96e8423b93718c70bd134fc81d&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/2df43ecf335d3a96e8423b93718c70bd134fc81d&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="5160602" author="rstam" created="Wed, 1 Feb 2023 22:29:29 +0000"  >&lt;p&gt;Thanks for reporting this issue, and for making it extra easy for me to reproduce by providing a minimal console app exhibiting the issue.&lt;/p&gt;

&lt;p&gt;This is similar to &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-4499&quot; title=&quot;Support Convert calls to a base type in filter translators&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-4499&quot;&gt;&lt;del&gt;CSHARP-4499&lt;/del&gt;&lt;/a&gt; but different because that was in the filter language translators and this is in the aggregation language translators. The same technique used to fix &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-4499&quot; title=&quot;Support Convert calls to a base type in filter translators&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-4499&quot;&gt;&lt;del&gt;CSHARP-4499&lt;/del&gt;&lt;/a&gt; works to fix this issue also, but it&apos;s slightly different code because it&apos;s in a different part of the code base.&lt;/p&gt;</comment>
                            <comment id="5158958" author="rstam" created="Wed, 1 Feb 2023 15:49:22 +0000"  >&lt;p&gt;Similar to but slightly different from &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-4499&quot; title=&quot;Support Convert calls to a base type in filter translators&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-4499&quot;&gt;&lt;del&gt;CSHARP-4499&lt;/del&gt;&lt;/a&gt;.&lt;/p&gt;</comment>
                            <comment id="5156889" author="JIRAUSER1270250" created="Tue, 31 Jan 2023 23:34:21 +0000"  >&lt;p&gt;Apologies for the odd formatting, it seems I&apos;m not able to make edits to my own ticket.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="2246816">CSHARP-4499</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                            <attachment id="429286" name="Program.cs" size="936" author="mirek@rynly.com" created="Tue, 31 Jan 2023 23:31:34 +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_10257" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Documentation Changes</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="11861"><![CDATA[Not Needed]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_14266" key="com.atlassian.jira.plugin.system.customfieldtypes:textarea">
                        <customfieldname>Documentation Changes Summary</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>&lt;p&gt;1.  What would you like to communicate to the user about this feature?&lt;br/&gt;
2.  Would you like the user to see examples of the syntax and/or executable code and its output?&lt;br/&gt;
3.  Which versions of the driver/connector does this apply to?&lt;/p&gt;</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|i1bu0o:</customfieldvalue>

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