<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:47:51 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-4311] LINQ translation bug when document class derives from Dictionary&lt;string, object&gt;</title>
                <link>https://jira.mongodb.org/browse/CSHARP-4311</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 the document class derives from Dictionary&amp;lt;string, object&amp;gt; and additionally has a property that is backed by a dictionary entry, LINQ does not work properly.&lt;/p&gt;
&lt;h4&gt;&lt;a name=&quot;Pleaseprovidetheversionofthedriver.Ifapplicable%2CpleaseprovidetheMongoDBserverversionandtopology%28standalone%2Creplicaset%2Corshardedcluster%29.&quot;&gt;&lt;/a&gt;Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).&lt;/h4&gt;

&lt;p&gt;MongoDB.Driver 2.17.1 on .NET 6&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;Consider following document class:&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;public class MyType: Dictionary&amp;lt;string, object&amp;gt;&lt;/tt&gt;&lt;br/&gt;
{{{}}&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonElement(&amp;quot;displayname&amp;quot;)&amp;#93;&lt;/span&gt;&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; public string DisplayName&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; {&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; get =&amp;gt; (string)this&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;displayname&amp;quot;&amp;#93;&lt;/span&gt;;&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; set =&amp;gt; this&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;displayname&amp;quot;&amp;#93;&lt;/span&gt; = value;&lt;/tt&gt;&lt;br/&gt;
{{&#160; &#160; }}}&lt;br/&gt;
&lt;tt&gt;}&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;Now if we try to do a LINQ query like&#160;&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;await collection.AsQueryable()&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; .Where(r =&amp;gt; r.DisplayName == &quot;Test&quot;)&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; &#160; &#160; .ToListAsync();&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;we get an InvalidOperationException &quot;The operands for operator &apos;Equal&apos; do not match the parameters of method &apos;op_Equality&apos;.&quot;&lt;/p&gt;

&lt;p&gt;Setting the LinqProvider to LinqProvider.V3 eliminates the exception, but the resulting list is always empty.&lt;/p&gt;

&lt;p&gt;Using &lt;tt&gt;.Where(r =&amp;gt; r&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;displayname&amp;quot;&amp;#93;&lt;/span&gt; == &quot;Test&quot;)&lt;/tt&gt; results in a correct non-empty result list.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</description>
                <environment></environment>
        <key id="2130822">CSHARP-4311</key>
            <summary>LINQ translation bug when document class derives from Dictionary&lt;string, object&gt;</summary>
                <type id="6" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14720&amp;avatarType=issuetype">Question</type>
                                            <priority id="10300" iconUrl="https://jira.mongodb.org/images/icons/priorities/medium.svg">Unknown</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="13203">Gone away</resolution>
                                        <assignee username="james.kovacs@mongodb.com">James Kovacs</assignee>
                                    <reporter username="mywyb2@gmail.com">Mo B.</reporter>
                        <labels>
                            <label>LINQ</label>
                    </labels>
                <created>Wed, 7 Sep 2022 14:30:04 +0000</created>
                <updated>Fri, 27 Oct 2023 19:56:02 +0000</updated>
                            <resolved>Tue, 27 Sep 2022 12:00:38 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="4857980" author="dbeng-pm-bot" created="Tue, 27 Sep 2022 12:00:40 +0000"  >&lt;p&gt;There hasn&apos;t been any recent activity on this ticket, so we&apos;re resolving it. Thanks for reaching out! Please feel free to comment on this if you&apos;re able to provide more information.&lt;/p&gt;</comment>
                            <comment id="4820736" author="james.kovacs" created="Mon, 12 Sep 2022 21:18:32 +0000"  >&lt;p&gt;Hi, Mo,&lt;/p&gt;

&lt;p&gt;Please see my comment on &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-4310&quot; title=&quot;ISupportInitialize methods not called when class derives from Dictionary&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-4310&quot;&gt;&lt;del&gt;CSHARP-4310&lt;/del&gt;&lt;/a&gt; for my explanation on why we do not recommend the strongly-typed property bag approach, which is essentially what deriving from &lt;tt&gt;Dictionary&amp;lt;string, object&amp;gt;&lt;/tt&gt; entails.&lt;/p&gt;

&lt;p&gt;As to why you get no results back from the query in LINQ3, the reason lies in how we serialize collection classes. When serializing collections, the expectation is that the collection is a list of values or name-value pairs. We do not expect serialization metadata in the form of BSON attributes. Thus &lt;tt&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;BsonElement(&amp;quot;displayname&amp;quot;)&amp;#93;&lt;/span&gt;&lt;/tt&gt; is never considered during the serialization and the resulting query is:&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;test.coll.Aggregate([{ &quot;$match&quot; : { &quot;DisplayName&quot; : &quot;Test&quot; } }])&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;You will notice that the query is on &lt;tt&gt;DisplayName&lt;/tt&gt; and not &lt;tt&gt;displayname&lt;/tt&gt;. These queries would work if your properties matched your database fields exactly (including casing). We still do not recommend the strongly-typed property bag approach, but you could make it work by any of the following means:&lt;/p&gt;

&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;Implement a custom &lt;tt&gt;IBsonSerializer&amp;lt;T&amp;gt;&lt;/tt&gt; that handled the casing differences&lt;/li&gt;
	&lt;li&gt;Change your database fields to match your C# property names (including casing)&lt;/li&gt;
	&lt;li&gt;Change your C# property names to match the database fields (including casing)&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Please let us know if you have any additional questions.&lt;/p&gt;

&lt;p&gt;Sincerely,&lt;br/&gt;
James&lt;/p&gt;</comment>
                            <comment id="4815720" author="JIRAUSER1257742" created="Fri, 9 Sep 2022 20:30:21 +0000"  >&lt;p&gt;Thanks &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=mywyb2%40gmail.com&quot; class=&quot;user-hover&quot; rel=&quot;mywyb2@gmail.com&quot;&gt;mywyb2@gmail.com&lt;/a&gt; for your report.&lt;/p&gt;

&lt;p&gt;Currently custom properties in Dictionary based types are not supported by standards serializers. So the mentioned code would not be supported.&lt;/p&gt;

&lt;p&gt;One option would be not using Dictionary bases types, and storing the additional data via BsonExtraElements: &lt;a href=&quot;https://mongodb.github.io/mongo-csharp-driver/2.17/reference/bson/mapping/#supporting-extra-elements&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://mongodb.github.io/mongo-csharp-driver/2.17/reference/bson/mapping/#supporting-extra-elements&lt;/a&gt;&lt;br/&gt;
Another workaround would be implementing custom serializer, and introducing TryGetMemberSerializationInfo method to handle correctly the additional properties naming translations used by LINQ.&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|i0ryu8:</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>