[EF-92] When Adding new Entity in Collection, entity object is not updated with ID Created: 18/Jan/24 Updated: 30/Jan/24 |
|
| Status: | In Code Review |
| Project: | Entity Framework |
| Component/s: | None |
| Affects Version/s: | Public Preview 1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Unknown |
| Reporter: | Steven Boivin | Assignee: | Damien Guard |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Greetings, I am inserting a new document into MongoDB following a a web API'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'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. For example, here is a short version of the code I'm attempting to use: protected override void OnModelCreating(ModelBuilder modelBuilder) ... internal class Request { public ObjectId _id \{ get; set; } public string status { get; set; } ... public async Task<string> CreateRequestAsync(MasterCandidateRequest request) await _database.Requests.AddAsync(requestDb); return requestDb._id.ToString(); 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. 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. Thank you. |