Using the following class:
public class C { public int Id { get; set; } [BsonRepresentation(BsonType.String)] public E1 E1 { get; set; } [BsonRepresentation(BsonType.String)] public E2 E2 { get; set; } }
where E1 and E2 are enums:
public enum E1 { A = 1, B = 2 } public enum E2 : ushort { A = 1, B = 2 }
The following query:
var result = queryable.FirstOrDefault(x => x.E1 == E1.B);
is correctly translated to:
"{ $match : { E1 : 'B' } }" "{ $limit : 1 }");
but a similar query using E2 instead:
var result = queryable.FirstOrDefault(x => x.E2 == E2.B);
is incorrectly translated to:
"{ $match : { E2 : 2 } }" "{ $limit : 1 }");
The issue is related to enum E2 being declared with an underlying type of ushort.