[CSHARP-234] Make the collection name accessible in IIdGenerator Created: 30/May/11 Updated: 02/Apr/15 Resolved: 02/Jun/11 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Feature Request |
| Affects Version/s: | 1.0 |
| Fix Version/s: | 1.1 |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Ahmed Zulkamal | Assignee: | Robert Stam |
| Resolution: | Done | Votes: | 0 |
| Labels: | insert | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Minor Change |
| Description |
|
Would be useful to also have the collection name accessible in IIdGenerator. |
| Comments |
| Comment by Ahmed Zulkamal [ 06/Jun/11 ] |
|
The secondary Id is generally meant for use in URLs. Keeping the ObjectId around is quite useful since it has the create date bundled together but as an URL-facing Id, it's just ugly. |
| Comment by Robert Stam [ 06/Jun/11 ] |
|
Not sure why you would need a secondary Id if ObjectId is already unique. The serializer doesn't sound like the right place to do it. And a custom IIdGenerator won't work either since it's only invoked on the primary Id. So sounds like you need to handle it some layer of your own code. |
| Comment by Ahmed Zulkamal [ 06/Jun/11 ] |
|
What would be your recommendation for populating a document that a ObjectId as the primary Id and a secondary HiLo Id? Would creating a custom serializer be useful or should the app's repository/service layer handle the assigning? |
| Comment by Robert Stam [ 02/Jun/11 ] |
|
This was a great suggestion. Thanks. Because IIdGenerator is in the BSON layer the implementation I chose is a little more abstract than you might have expected. GenerateId is now defined as: object GenerateId(object container, object document); but when called from the C# driver the value of container will always be an instance of MongoCollection. Once you cast the value to a MongoCollection you can get the name of the collection, as well as anything else you need to know about the collection. This is a backward breaking change, but only for the very few users who might have implemented an IIdGenerator. The fix for them is trivial. |