<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:26:50 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>[EF-71] Mapping of ObjectIds to strings in entities</title>
                <link>https://jira.mongodb.org/browse/EF-71</link>
                <project id="22583" key="EF">Entity Framework</project>
                    <description>&lt;p&gt;When mapping MongoDB documents to C# classes, having string properties in the classes simplifies the handling of ObjectIds very much. In the existing driver for C#, this can be done by applying an &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonRepresentation(BsonType.ObjectId)&amp;#93;&lt;/span&gt;-attribute to the property (also works if the property is an array or enumeration). However, this had no effect for the EF provider.&#160;&lt;/p&gt;

&lt;p&gt;Also, adding a conversion when defining the model did not help, but led to an exception:&#160;&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;modelBuilder.Entity&amp;lt;Movie&amp;gt;()&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; .ToCollection(&quot;movies&quot;)&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; .Property(x =&amp;gt; x.Id)&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; .HasElementName(&quot;_id&quot;)&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; .HasConversion(x =&amp;gt; ObjectId.Parse&lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/error.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;, x =&amp;gt; x.ToString());&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;Exception:&#160;&lt;br/&gt;
System.FormatException: Cannot deserialize a &apos;String&apos; from BsonType &apos;ObjectId&apos;.&lt;br/&gt;
at MongoDB.Bson.Serialization.Serializers.StringSerializer.DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)&lt;br/&gt;
at MongoDB.Bson.Serialization.Serializers.SealedClassSerializerBase`1.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)&lt;br/&gt;
at MongoDB.Bson.Serialization.Serializers.SerializerBase`1.MongoDB.Bson.Serialization.IBsonSerializer.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)&lt;br/&gt;
at MongoDB.Bson.Serialization.IBsonSerializerExtensions.Deserialize(IBsonSerializer serializer, BsonDeserializationContext context)&lt;br/&gt;
at MongoDB.Bson.Serialization.BsonSerializationInfo.DeserializeValue(BsonValue value)&lt;br/&gt;
at MongoDB.EntityFrameworkCore.Serializers.SerializationHelper.ReadElementValue&lt;span class=&quot;error&quot;&gt;&amp;#91;T&amp;#93;&lt;/span&gt;(BsonDocument document, BsonSerializationInfo elementSerializationInfo)&lt;br/&gt;
Using strings instead of an ObjectId type also simplifies the JSON serialization of the class. ObjectId objects are serialized like this by default:&#160;&lt;/p&gt;

{ &quot;timestamp&quot;: 1463423888, &quot;machine&quot;: 15897363, &quot;pid&quot;: -13653, &quot;increment&quot;: 13451573, &quot;creationTime&quot;: &quot;2016-05-16T18:38:08Z&quot; }

&lt;p&gt;This format is neither recognizable as an ObjectId by a human, nor can it be used as URL parameter in an API easily. So one would have to create a custom serializer for the API anyway; better yet if the EF provider supported the mapping in the same way as the existing driver for C#.&#160;&lt;/p&gt;

&lt;p&gt;Additional side info: creating an EDM-model for OData based upon the class also had difficulties with the id&#160; being an ObjectId; I expect this to handle a string without a problem.&lt;/p&gt;

&lt;p&gt;(sorry, I&apos;m not a MongoDB employee so I had to create a bug issue for this. From my point of view, it&apos;s more of an improvement - but an important one)&lt;/p&gt;</description>
                <environment></environment>
        <key id="2491492">EF-71</key>
            <summary>Mapping of ObjectIds to strings in entities</summary>
                <type id="2" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14711&amp;avatarType=issuetype">New Feature</type>
                                            <priority id="2" iconUrl="https://jira.mongodb.org/images/icons/priorities/critical.svg">Critical - P2</priority>
                        <status id="10038" iconUrl="https://jira.mongodb.org/images/icons/subtask.gif" description="">Backlog</status>
                    <statusCategory id="2" key="new" colorName="default"/>
                                    <resolution id="-1">Unresolved</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="m.wildgruber@sevantage.de">Markus Wildgruber</reporter>
                        <labels>
                    </labels>
                <created>Mon, 6 Nov 2023 14:08:45 +0000</created>
                <updated>Tue, 14 Nov 2023 20:36:42 +0000</updated>
                                            <version>Public Preview 1</version>
                                                                        <votes>4</votes>
                                    <watches>6</watches>
                                                                                                                <comments>
                            <comment id="5857880" author="esha.bhargava" created="Mon, 6 Nov 2023 17:13:34 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=m.wildgruber%40sevantage.de&quot; class=&quot;user-hover&quot; rel=&quot;m.wildgruber@sevantage.de&quot;&gt;m.wildgruber@sevantage.de&lt;/a&gt; Thank you for your suggestion. We&apos;ll consider it for a future version.&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|i2gtw4:</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>