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

Can't Map Base Class Field As Id

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.4
    • Affects Version/s: 1.3.1
    • Component/s: None
    • None

      This code from the docs:

      BsonClassMap.RegisterClassMap<MyClass>(cm => {
          cm.AutoMap();
          cm.SetIdMember(cm.GetMemberMap(c => c.SomeProperty));
      });
      

      ...fails if SomeProperty is on a base of MyClass.

      Based on another issues I read (CSHARP-396) I thought this might work:

      BsonClassMap.RegisterClassMap<BaseOfMyClass>(cm => {
          cm.SetIdMember(x.GetMemberMap(c => c.SomeProperty));
      });
      

      But that fails too. Both cases fail with cryptic message "Invalid memberMap."

      The only workaround for mapping via code seems to be remove inheritance.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            timscott Tim Scott
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: