-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 2.8.1
-
Component/s: Serialization
-
None
Some applications want to keep their POCO classes free of any dependency on C# driver classes. That includes the _id field which typically is an ObjectId.
One viable approach is to declare the _id as type string, and convert from ObjectId to string when deserializing and from string back to ObjectId when serializing.
This is currently possible using attributes to annotate the POCO, but that defeats the goal of keeping the POCOs free of any dependency on C# driver classes.
This ticket is to add support for a convention-only approach to mapping _id fields between string in the application and ObjectId in the database.
There is an existing convention called `StringObjectIdIdGeneratorConvention` that is related to this goal, but only addresses a subset of this goal. What this convention does is add an appropriate IdGenerator to the IdMemberMap if and only if the Id member is a string that is already configured to be stored as an ObjectId in the database. But that requires that the IdMember already be configured to be stored as an ObjectId in the database.
A useful new convention would be one that simultaneously configures the string _id field to be stored as an ObjectId in the database and configures the appropriate IdGenerator.