[CSHARP-633] LINQ queries against collections of type MongoCollection<BsonDocument> are not supported Created: 23/Nov/12  Updated: 02/Apr/15  Resolved: 22/Nov/13

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.6.1
Fix Version/s: 1.9

Type: Improvement Priority: Major - P3
Reporter: Teodor Georgiev Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File Mongo.rar    

 Description   

var collection = database.GetCollection("testconnection");
dynamic p = new MongoDB.Bson.ObjectModel.BsonDynamicDocument();

p.Id = Guid.NewGuid();
collection.Insert(p);
var value = (Guid)p.Id;
var item2 = collection.AsQueryable().Where(item => item.GetValue("Id") == value).FirstOrDefault();

this is giving an error.

I have attached a sample project and you can see it there.



 Comments   
Comment by Craig Wilson [ 22/Nov/13 ]

RC in December. Probably full release in early January.

Comment by Nebojsa Veron [ 22/Nov/13 ]

Sounds great, when do you think 1.9 driver will be released?

Comment by Craig Wilson [ 22/Nov/13 ]

This has been added to 1.9 and is already in master branch. Syntax would look like this:

// { "x.y" : { "$gt" : 10 } }
var results = from c in col.AsQueryable()
                    where c["x"]["y"] > 10
                    select c;

Comment by Nebojsa Veron [ 21/Nov/13 ]

This is still not supported in version 1.8.3?

Comment by Teodor Georgiev [ 26/Nov/12 ]

Probably will go with Linq provider. That's not so complicated. I have done it already couple of times. Thank you for the response.

Comment by Craig Wilson [ 26/Nov/12 ]

Well, it's now on the list and we won't remove it. Also, feel free to submit a pull request at github adding this support into the existing linq provider. That's probably much simpler than rewriting it...

Comment by Teodor Georgiev [ 26/Nov/12 ]

Currently I am trying to build a framework based on C# that is using partially dynamic partially strongly typed objects. That's why i am using BsonDocument. Apart of that i would like to have a way to query object's dynamic properties and this is the reason why I am asking if you are planing to support this feature. In case that you will not support that I will have to rewrite your Linq provider to be able to do that.

Comment by Craig Wilson [ 26/Nov/12 ]

This is the first time it has been added to the list. May I ask why you want to use Linq with a BsonDocument? It's a relatively large overhead for very little benefit. As you can see, there is a relatively simple workaround for this that also happens to be syntactically shorter.

// preferred way to write this query...
collection.FindOne(Query.Eq("Id", value));

Comment by Teodor Georgiev [ 26/Nov/12 ]

Are you planing to support similar feature?

Comment by Robert Stam [ 24/Nov/12 ]

We don't currently support LINQ queries against collections of type MongoCollection<BsonDocument>. LINQ queries are only supported against C# classes that expose their queryable values as public properties (or fields).

I've changed the description of this issue to more accurately reflect that fact.

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