[CSHARP-759] When calling Save with a custom ID generator in place, the default is Insert instead of Upsert Created: 13/Jun/13 Updated: 20/Mar/14 Resolved: 27/Jun/13 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 1.8.1 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Wade Kaple | Assignee: | Robert Stam |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows 7, Visual Studio 2012 |
||
| Description |
|
I have implemented a custom ID generator that is a hash of a couple of other fields in our document to create a single key out of a combination key. When Iregister this generator and call Save, passing in an object of our document type, if the IsEmpty method of our IIDGenerator implementation returns true, the GenerateId method is called, and then Insert is called. Since the Save method is supposed to be an more of an upsert, it feels more natural that this would call Update with the Upsert flag set as is done a few lines later in the code if the IsEmpty method returns false (however in this case, the custom generator is not called). |
| Comments |
| Comment by Robert Stam [ 27/Jun/13 ] |
|
If the Id is empty and a new value is generated then we know for sure that this a new document and calling Insert is slightly more efficient than calling Update with the Upsert flag set. If the Id has a non-empty value then we can't know if it's a new document or not, which is why in this case we always do an upsert. This behavior is by design. All drivers implement Save the same way. |