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

SetOrder doesn't seem to order the field in the document

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.4.1
    • Component/s: Serialization
    • Labels:
      None

      Description

      I have a class, Foo, that looks like the following.

      public class Foo
      {
      	public ObjectId Id { get; set; }
      	public string A { get; set; }
      	public string B { get; set; }
      	public string C { get; set; }
      }
      

      And I map the class as follows

      BsonClassMap.RegisterClassMap<Foo>(cm =>
      {
      	cm.AutoMap();
      	cm.MapMember(c => c.A).SetOrder(3);
      	cm.MapMember(c => c.B).SetOrder(2);
      	cm.MapMember(c => c.C).SetOrder(1);
      });
      

      I expect my document to look like the following

      > db.foo.findOne()
      {
              "_id" : ObjectId("58407cb1a589ca66b0d0ac48"),
              "C" : "0",
              "B" : "2016",
              "A" : "Jan"
      }
      

      But they actually look like this.

      > db.foo.findOne()
      {
              "_id" : ObjectId("58407bf8a589ca8f5cedb77b"),
              "A" : "Jan",
              "B" : "2016",
              "C" : "0"
      }
      

      In order to get the desired order, I have to do the following mapping, making AutoMap last.

      BsonClassMap.RegisterClassMap<Foo>(cm =>
      {
      	cm.MapMember(c => c.A).SetOrder(3);
      	cm.MapMember(c => c.B).SetOrder(2);
      	cm.MapMember(c => c.C).SetOrder(1);
      	cm.AutoMap();
      });
      

      These should either be independent of order or we need to be explicit that SetOrder needs to come first.

        Attachments

          Activity

            People

            Assignee:
            rstam Robert Stam
            Reporter:
            peter.garafano Peter Garafano
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: