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

Can't Map Base Class Field As Id

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 1.4
    • 1.3.1
    • None
    • None

    Description

      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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: