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

Expressions used to resolve field names for enum members do not work

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor - P4 Minor - P4
    • 2.4.1
    • 2.0
    • Serialization
    • None
    • Win8.1

    Description

      Given the class and enum:

      class Person
      {
      	public Color FavoriteColor { get; set; }
      }
       
      enum Color
      {
      	Blue,
      	SomethingElse
      }
      

      The following code snippet will not work:

      Builders<Person>.IndexKeys.Ascending(x => x.FavoriteColor);
      Builders<Person>.Filter.Eq(x => x.FavoriteColor, Color.Blue);
      // other builders as well
      

      Workaround

      Use the string field name of the member. Even if you have mapped it to a different element name, as long as the member name is used, it will still get mapped:

      Builders<Person>.IndexKeys.Ascending("FavoriteColor");
      

      Attachments

        Activity

          People

            robert@mongodb.com Robert Stam
            nick@innsenroute.com Nick Judson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: