<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:26:53 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-92] When Adding new Entity in Collection, entity object is not updated with ID</title>
                <link>https://jira.mongodb.org/browse/EF-92</link>
                <project id="22583" key="EF">Entity Framework</project>
                    <description>&lt;p&gt;Greetings,&lt;/p&gt;

&lt;p&gt;I am inserting a new document into MongoDB following a a web API&apos;s POST and then wish to redirect to a GET of the new object using its ID. To do so, I am trying to recover the ObjectId after the new entry is in the database. Based from general Entity Framework documentations, this would normally be a non-issue as when executing SaveChanges(), the entity object in the code that was used to make the insert should be updated with any value generated on the database side such as _id. This doesn&apos;t seem to be the case here. I confirm that my entity is in MongoDB and has its _id but the entity object on the code side remains the default value.&lt;/p&gt;

&lt;p&gt;For example, here is a short version of the code I&apos;m attempting to use:&lt;/p&gt;

&lt;p&gt;&lt;sub&gt;protected override void OnModelCreating(ModelBuilder modelBuilder)&lt;/sub&gt;&lt;br/&gt;
&lt;sub&gt;{&lt;/sub&gt;&lt;br/&gt;
&#160; &#160; &lt;sub&gt;base.OnModelCreating(modelBuilder);&lt;/sub&gt;&lt;br/&gt;
&#160; &#160; &lt;sub&gt;modelBuilder.Entity&amp;lt;Request&amp;gt;().ToCollection(&quot;requests&quot;);&lt;/sub&gt;&lt;br/&gt;
&lt;sub&gt;}&lt;/sub&gt;&lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;

&lt;p&gt;internal class Request&lt;/p&gt;
{
&#160; &#160; public ObjectId _id \{ get; set; }
&lt;p&gt;&#160; &#160; public string status { get; set; }&lt;br/&gt;
&#160; &#160; ...&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;

&lt;p&gt;&lt;sub&gt;public async Task&amp;lt;string&amp;gt; CreateRequestAsync(MasterCandidateRequest request)&lt;/sub&gt;&lt;br/&gt;
&lt;sub&gt;{&lt;/sub&gt;&lt;br/&gt;
&#160; &#160; &lt;sub&gt;try&lt;/sub&gt;&lt;br/&gt;
&#160; &#160; &lt;sub&gt;{&lt;/sub&gt;&lt;br/&gt;
&#160; &#160; &#160; &#160; &lt;sub&gt;var requestDb = new Request()&lt;/sub&gt;&lt;br/&gt;
&#160; &#160; &#160; &#160; &lt;sub&gt;{&lt;/sub&gt;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &lt;sub&gt;attemptRetry = false,&lt;/sub&gt;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &lt;sub&gt;...&lt;/sub&gt;&lt;br/&gt;
&#160; &#160; &#160; &#160; &#160; &#160; &lt;sub&gt;status = RequestStatus.Ongoing.ToString()&lt;/sub&gt;&lt;br/&gt;
&#160; &#160; &#160; &#160; &lt;sub&gt;};&lt;/sub&gt;&lt;/p&gt;

&lt;p&gt;&#160; &#160; &#160; &#160; &lt;sub&gt;await _database.Requests.AddAsync(requestDb);&lt;/sub&gt;&lt;br/&gt;
&#160; &#160; &#160; &#160; &lt;sub&gt;await _database.SaveChangesAsync();&lt;/sub&gt;&lt;/p&gt;

&lt;p&gt;&#160; &#160; &#160; &#160; &lt;sub&gt;return requestDb._id.ToString();&lt;/sub&gt;&lt;br/&gt;
&#160; &#160; &lt;sub&gt;}&lt;/sub&gt;&lt;br/&gt;
&#160; &#160; &lt;sub&gt;catch (Exception e)&lt;/sub&gt;&lt;br/&gt;
&#160; &#160; &lt;sub&gt;{&lt;/sub&gt;&lt;br/&gt;
&#160; &#160; &#160; &#160; &lt;sub&gt;return string.Empty;&lt;/sub&gt;&lt;br/&gt;
&#160; &#160; &lt;sub&gt;}&lt;/sub&gt;&lt;br/&gt;
&lt;sub&gt;}&lt;/sub&gt;&lt;/p&gt;

&lt;p&gt;General documentation for Entity Framework claims that requestDb._id at the moment of the return should now contain the value as it is after SaveChanges and the entry is successfully added on MongoDB. However, it is still the default value of 0s that it was when the Add was called.&lt;/p&gt;

&lt;p&gt;Is this a bug, a limitation of the current Preview or am I missing something on my side? I have mostly followed the Quick Start and Quick Reference pages to do this implementation so I am not sure if I am missing something.&lt;/p&gt;

&lt;p&gt;Thank you.&lt;/p&gt;</description>
                <environment></environment>
        <key id="2550735">EF-92</key>
            <summary>When Adding new Entity in Collection, entity object is not updated with ID</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="10300" iconUrl="https://jira.mongodb.org/images/icons/priorities/medium.svg">Unknown</priority>
                        <status id="10018" iconUrl="https://jira.mongodb.org/images/icons/statuses/visible.png" description="">In Code Review</status>
                    <statusCategory id="4" key="indeterminate" colorName="inprogress"/>
                                    <resolution id="-1">Unresolved</resolution>
                                        <assignee username="damien.guard@mongodb.com">Damien Guard</assignee>
                                    <reporter username="steven.boivin@ubisoft.com">Steven Boivin</reporter>
                        <labels>
                    </labels>
                <created>Thu, 18 Jan 2024 22:42:47 +0000</created>
                <updated>Tue, 30 Jan 2024 14:35:56 +0000</updated>
                                            <version>Public Preview 1</version>
                                                                        <votes>1</votes>
                                    <watches>1</watches>
                                                                                                                        <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                        <customfield id="customfield_23812" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                        <customfieldname>Assigned Team</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="26445"><![CDATA[Dotnet Drivers]]></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|i2qra4:</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>