Thanks for reaching out. In C#, enums are converted by the C# compiler to their underlying type, in this case an int. Our LINQ provider receives the AST (including the casts to int) and tries to undo them instead rendering the correct type - in this case a string - in the MQL.
You can view the MQL from the query by calling ToString() on the query or using the MongoDB Analyzer to view the MQL.
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
var client = new MongoClient();
var db = client.GetDatabase("test");
var coll = db.GetCollection<Entity>("coll");
var query = coll.AsQueryable().Where(x => x.LanguageAsInt32 == Language.English && x.LanguageAsString == Language.English);
Console.WriteLine(query.ToString());
classEntity {
public ObjectId Id { get; set; }
publicstring Name { get; set; }
public Language LanguageAsInt32 { get; set; }
[BsonRepresentation(BsonType.String)]
public Language LanguageAsString { get; set; }
}
enum Language {
English = 42
}
Running this program with the .NET/C# Driver 3.1.0 results in the following output: