[CSHARP-556] SelectMany LINQ operator not supported Created: 07/Sep/12  Updated: 20/Jan/16  Resolved: 08/May/15

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: 1.6
Fix Version/s: 2.1

Type: New Feature Priority: Minor - P4
Reporter: Travis Krick Assignee: Craig Wilson
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

windows 2k8 r2, using mongodb version 2.0.6 64-bit, using driver 1.6


Issue Links:
Duplicate
is duplicated by CSHARP-912 Support SelectMany where subset comes... Closed
Epic Link: Rewrite Linq

 Description   

Lets say i have this simplified version of my task workflow:
public class TaskGraph
{
[BsonId]
public BsonObjectId Id

{ get; set; }
public List<Task> Tasks { get; set; }

}

public class Task
{
[BsonId]
public Guid Id

{ get; set; }
public string AssignedTo { get; set; }

// other stuff elided
}

In this case, the following query (where I'm trying to get all tasks assigned to me regardless of which workflow they are a part of):

var db = DBUtils.GetMongoDB("taskpoc");
var queryCtx = db.GetCollection<TaskGraph>("TaskGraphs").AsQueryable();
var tasksAssignedToMe = queryCtx
.SelectMany(tg => tg.Tasks)
.Where(t => t.AssignedTo == "tkrick");

... throws the following exception:
System.NotSupportedException

{"The SelectMany query operator is not supported."}

This feature is to enable this to return those results.



 Comments   
Comment by Githook User [ 08/May/15 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-556: Added support for SelectMany at the root level.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/3344e791464ddafb7b28fe1a666f445646783d59

Comment by Robert Stam [ 01/Nov/12 ]

Just to be clear, projection is already supported, just not in the most efficient way that is theoretically possible, since we always fetch the entire document and then do the projection. Projection does not require limiting the fields returned from the server, but rather limiting the fields is an optimization made possible by projection.

We are definitely planning to use the projection to control which fields actually need to be returned from the server. See CSHARP-456.

Comment by Travis Krick [ 01/Nov/12 ]

Understood. If hard to implement, projection can come in 2.0. but personally disagree with the downgrade to minor aspect. Not attempting to patronize, but with large docs, projection could limit the amount of data sent across the wire if a query returns many results. Projection [vertical slicing] is one of the main data operations, among filtering [horizontal slicing], sorting, and grouping. The main differentiating factor for c# is linq, so this driver supporting as much of that functionality as possible would be great. Thanks for the hard work, much appreciated.

Comment by Craig Wilson [ 29/Oct/12 ]

SelectMany is actually a very difficult operator to support. We currently don't support Select either in the sense that it will still pull back the full document and run the projection client-side.

Since there is another way to accomplish what you are doing by forming the query differently, I'm going to downgrade this to a minor feature and target it at 2.0

  var tasksAssignedToMe = queryCtx.Where(tg =>tg.Tasks.Any(t => t.AssignedTo == "tkrick");

This will pull back all the TaskGraphs that have tasks assigned to you. Subsequently, you can filter out the tasks client-side.

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