<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:38:12 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-921] Any subquery fails for Nullable&lt;ObjectId&gt; comparison</title>
                <link>https://jira.mongodb.org/browse/CSHARP-921</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Take these queries and try to run them. You will get the following exception:&lt;/p&gt;

&lt;p&gt;ObjectId?[] supplierIds =&lt;br/&gt;
	(from s in mongo.Suppliers&lt;br/&gt;
		where s.Country == supplierCountry&lt;br/&gt;
		select new Nullable&amp;lt;ObjectId&amp;gt;(s.Id)).ToArray();&lt;/p&gt;

&lt;p&gt;var supplierProducts =&lt;br/&gt;
	(from p in mongo.Products&lt;br/&gt;
		where supplierIds.Any(id =&amp;gt; id == p.SupplierID)&lt;br/&gt;
		orderby p.ProductName&lt;br/&gt;
		select p);&lt;/p&gt;


&lt;p&gt;Unhandled Exception: System.NotSupportedException: Unable to determine the serialization information for the expression: Nullable&amp;lt;ObjectId&amp;gt;[]:&lt;/p&gt;
{ 000000000000000000000016, 000000000000000000000019, 000000000000000000000002, 000000000000000000000003 }
&lt;p&gt;.&lt;br/&gt;
   at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder.GetSerializationInfo&lt;br/&gt;
(Expression node, Dictionary`2 serializationInfoCache)&lt;br/&gt;
   at MongoDB.Driver.Linq.PredicateTranslator.BuildAnyQuery(MethodCallExpression&lt;br/&gt;
 methodCallExpression)&lt;br/&gt;
   at MongoDB.Driver.Linq.PredicateTranslator.BuildMethodCallQuery(MethodCallExp&lt;br/&gt;
ression methodCallExpression)&lt;br/&gt;
   at MongoDB.Driver.Linq.PredicateTranslator.BuildQuery(Expression expression)&lt;br/&gt;
   at MongoDB.Driver.Linq.SelectQuery.BuildQuery()&lt;br/&gt;
   at MongoDB.Driver.Linq.SelectQuery.Execute()&lt;br/&gt;
   at MongoDB.Driver.Linq.MongoQueryProvider.Execute(Expression expression)&lt;br/&gt;
   at MongoDB.Driver.Linq.MongoQueryable`1.GetEnumerator()&lt;/p&gt;

&lt;p&gt;An alternate attempt at that query with ObjectId[] rather than ObjectId[] gives basically the same failure:&lt;/p&gt;

&lt;p&gt;ObjectId[] supplierIds =&lt;br/&gt;
	(from s in mongo.Suppliers&lt;br/&gt;
		where s.Country == supplierCountry&lt;br/&gt;
		select s.Id).ToArray();&lt;/p&gt;

&lt;p&gt;var supplierProducts =&lt;br/&gt;
	(from p in mongo.Products&lt;br/&gt;
		where supplierIds.Any(id =&amp;gt; id == p.SupplierID)&lt;br/&gt;
		orderby p.ProductName&lt;br/&gt;
		select p);&lt;/p&gt;

&lt;p&gt;However, if I use Contains rather than Any, it works! But it is more painful because I need to convert to an nullable ObjectId array when the source is not actually nullable (required so supplierIds.Contains() compiles):&lt;/p&gt;

&lt;p&gt;ObjectId?[] supplierIds =&lt;br/&gt;
	(from s in mongo.Suppliers&lt;br/&gt;
		where s.Country == supplierCountry&lt;br/&gt;
		select new Nullable&amp;lt;ObjectId&amp;gt;(s.Id)).ToArray();&lt;/p&gt;

&lt;p&gt;var supplierProducts =&lt;br/&gt;
	(from p in mongo.Products&lt;br/&gt;
		where supplierIds.Contains(p.SupplierID)&lt;br/&gt;
		orderby p.ProductName&lt;br/&gt;
		select p);&lt;/p&gt;

&lt;p&gt;I&apos;ve attached the two related classes involved in the query.&lt;/p&gt;</description>
                <environment></environment>
        <key id="117853">CSHARP-921</key>
            <summary>Any subquery fails for Nullable&lt;ObjectId&gt; comparison</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="2">Won&apos;t Fix</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="mkennedy66996693">Michael Kennedy</reporter>
                        <labels>
                    </labels>
                <created>Wed, 5 Mar 2014 17:45:11 +0000</created>
                <updated>Tue, 23 Jun 2015 16:18:16 +0000</updated>
                            <resolved>Wed, 5 Mar 2014 20:31:42 +0000</resolved>
                                    <version>1.8.3</version>
                                                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="510109" author="mkennedy66996693" created="Wed, 5 Mar 2014 19:40:26 +0000"  >&lt;p&gt;Make sense. It&apos;s slightly more painful to write the contains because of the type mismatch but that&apos;s somewhat a weakness of C# not being able to answer does a nullable value type live in a non-nullable typed array.&lt;/p&gt;

&lt;p&gt;Thanks for the feedback.&lt;/p&gt;</comment>
                            <comment id="509975" author="craiggwilson" created="Wed, 5 Mar 2014 17:53:24 +0000"  >&lt;p&gt;Interesting use case.  I&apos;m inclined to mark this as won&apos;t fix unless I&apos;m missing something.&lt;/p&gt;

&lt;p&gt;What gets translated when using Contains on a local &quot;array&quot; is an $in clause is generated.  {x: { $in : &lt;span class=&quot;error&quot;&gt;&amp;#91;1,2,3&amp;#93;&lt;/span&gt;}}.  The problem with supporting Any in this fashion is that there is only 1 version of Any that would actually be legitimate (and it happens to be the one you are using).  It takes the form of localArray.Any(item =&amp;gt; item == value).  If any other type of comparison is used inside the Any predicate, it no longer has a valid translation to MongoDB query syntax (or at least an efficient one).&lt;/p&gt;

&lt;p&gt;As such, using Contains on the local &quot;array&quot; is the supported form for this type of query.  Thoughts?&lt;/p&gt;</comment>
                            <comment id="509964" author="mkennedy66996693" created="Wed, 5 Mar 2014 17:46:34 +0000"  >&lt;p&gt;I should probably have entitled this &lt;/p&gt;

&lt;p&gt;IQueryable&amp;lt;T&amp;gt;.Any subquery fails for ObjectId[]  comparison.&lt;/p&gt;

&lt;p&gt;I originally wanted to use ObjectId[] but had to move to ObjectId?[] to use Contains (which is effectively the same but works).&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="38943" name="Product.cs" size="671" author="mkennedy66996693" created="Wed, 5 Mar 2014 17:45:11 +0000"/>
                            <attachment id="38944" name="Supplier.cs" size="712" author="mkennedy66996693" created="Wed, 5 Mar 2014 17:45:11 +0000"/>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10038"><![CDATA[Fully Compatible]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <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|hrwj8n:</customfieldvalue>

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