-
Type: Question
-
Resolution: Gone away
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
Summary
When the document class derives from Dictionary<string, object> and additionally has a property that is backed by a dictionary entry, LINQ does not work properly.
Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).
MongoDB.Driver 2.17.1 on .NET 6
How to Reproduce
Consider following document class:
public class MyType: Dictionary<string, object>
{{{}}
[BsonElement("displayname")]
public string DisplayName
{
get => (string)this["displayname"];
set => this["displayname"] = value;
{{ }}}
}
Now if we try to do a LINQ query like
await collection.AsQueryable()
.Where(r => r.DisplayName == "Test")
.ToListAsync();
we get an InvalidOperationException "The operands for operator 'Equal' do not match the parameters of method 'op_Equality'."
Setting the LinqProvider to LinqProvider.V3 eliminates the exception, but the resulting list is always empty.
Using .Where(r => r["displayname"] == "Test") results in a correct non-empty result list.