Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is AsQueryable method departed in new Mongodb C# driver 2.0rc?

Tags:

First of all I'm new to MongoDb. In MongoDb C# driver 1.9.x, i can take collections as queryable with AsQueryable method like this.

        var db = client.GetServer().GetDatabase("test");         var col = db.GetCollection("Video");         var qrlist = col.AsQueryable(); 

I installed new driver 2.0rc and while using it, i cannot use AsQueryable method because it is missing. Is it departed or is there another way to accomplish this? (I have already included MongoDB.Driver.Linq).

        var db = client.GetDatabase("test");         var col = db.GetCollection<Contact>("Contact"); //GetCollection without <T> is missing to.         var qrlist = col.AsQueryable(); // AsQueryable missing here. 

How can i get my entities as queryable in new driver, need help from MongoDb gurus. Thank you.

like image 237
ilker unal Avatar asked Mar 18 '15 14:03

ilker unal


People also ask

Why do we use AsQueryable () on collection?

AsQueryable is a method that allow the query to be converted to an instance of IQueryable. When you use AsQueryable operator on an existing query and apply further transformations such as applying a filter or specifying a sort order, those lambda statements are converted to Expression trees.

What is AsQueryable C#?

AsQueryable() in C# AsQueryable() method is used to get an IQueryable reference. Let us see an example to find sum of integer values. Firstly, set an integer array. var arr = new int[] { 100, 200, 300, 400 };


1 Answers

19 October update:

MongoDB 2.1 driver is out https://github.com/mongodb/mongo-csharp-driver/releases/tag/v2.1.0

It supports LINQ:

LINQ

CSHARP-935 LINQ support has been rewritten and now targets the aggregation framework. It is a more natural translation and enables many features of LINQ that were previously not able to be translated.

Simply use the new AsQueryable method to work with LINQ.

18 September update:

MongoDB 2.1 driver RC should support it. See https://jira.mongodb.org/browse/CSHARP-935

Finally 2.1 rc came out. Great work!

Old answer:

No, AsQueryable is unsupported: https://jira.mongodb.org/browse/CSHARP-935

Type: Epic Status:OPEN Priority: Major - P3 Resolution: Unresolved

And from the hourse's mouth: Craig Wilson on the google forum

Yes, there is currently no AsQueryable on the new api. You can track this feature here (https://jira.mongodb.org/browse/CSHARP-935). We simply didn't have enough time to get it completed and tested thoroughly. It is scheduled for 2.1 and is a priority for us. Until then, we have integrated expression tree functionality into the Find and Aggregate methods (and some of the write methods for filtering) such that you may not need a full LINQ implementation. For instance, see the sample test class here as an example: https://github.com/mongodb/mongo-csharp-driver/blob/master/src/MongoDB.Driver.Tests/Samples/AggregationSample.cs#L77

like image 70
xanatos Avatar answered Sep 28 '22 10:09

xanatos