[CSHARP-481] Implement Dictionary<String, T>.ContainsKey in Linq Provider Created: 30/May/12  Updated: 02/Apr/15  Resolved: 04/Jun/12

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.4.2
Fix Version/s: 1.5

Type: New Feature Priority: Major - P3
Reporter: Tim Kellogg Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: dict, linq
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Mongo v2.0.3, C# Driver v1.4.2


Backwards Compatibility: Fully Compatible

 Description   

Can we please implement Dictionary<String, T>.ContainsKey in the Linq provider? It seems like this would be appropriate.



 Comments   
Comment by Robert Stam [ 30/May/12 ]

Note to implementer: at the same time consider other methods, including extension methods, of IDictionary<TKey, TValue> that would be appropriate to implement.

Comment by Robert Stam [ 30/May/12 ]

And here's a workaround for now:

var query =
    from c in collection.AsQueryable<C>()
    //where c.D.ContainsKey("x")
    where Query.Exists("D.x", true).Inject()
    select c;

which uses the Inject method to inject a standard MongoDB query into a LINQ query.

Comment by Robert Stam [ 30/May/12 ]

Sample code to reproduce using this class:

public class C
{
    public int Id;
    public Dictionary<string, int> D;
}

and a query like this:

var query =
    from c in collection.AsQueryable<C>()
    where c.D.ContainsKey("x")
    select c;

Generated at Wed Feb 07 21:36:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.