Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2644

Add a convention for storing an _id declared as string in a POCO as ObjectId in the database

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.9.0
    • 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.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            robert@mongodb.com Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: