[CSHARP-2706] Add AsQueryable to IMongoDbCollection rather than as an extension method. Created: 23/Aug/19  Updated: 27/Oct/23  Resolved: 19/Oct/19

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

Type: Improvement Priority: Major - P3
Reporter: Richard Collette Assignee: Robert Stam
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Linq will "discover" and use the AsQueryable interface if it is not defined as extension method.

 



 Comments   
Comment by Robert Stam [ 19/Oct/19 ]

I think the current design is appropriate because:

  1. Calling AsQueryable explicitly is a clean API point to provide additional arguments
  2. It provides a clean separation between a the driver collection API and the LINQ API

I appreciate that there would be a small convenience to being able to omit the call to AsQueryable, but for now at least we're going to not change this.

Comment by Robert Stam [ 25/Sep/19 ]

Oh... the Summary field said "Add AsQueryable to IMongoDBCollection", but you meant "Should IMongoDBCollection implement IQueryable?".

I suppose that's a possibility. The current approach of using the AsQueryable extension method allows the opportunity to pass in the AggregateOptions that should be used when executing the LINQ query.

We'd have to think more thoroughly about the implications of changing IMongoDBCollection to implement IQueryable directly to make sure there are no unintended side effects or undesirable consequences.

Comment by Richard Collette [ 17/Sep/19 ]

I am not talking about IDE behavior.

The framework does not see IMongoDbCollection as an IQueryable implementation because, well, it isn't.   I don't know what the framework does specifically ( I could dig if you really want) but I suspect that it's just checking if  the type is IQueryable and calling the AsQueryable method.

If IMongoDbCollection implemented IQueryable, IQueryable<T> directly, rather than as an extensions method,  it would not be necessary to to call the AsQueryable method when creating LINQ queries.  It's actually abnormal to have to do so under normal circumstances.

 

Comment by Jeffrey Yemin [ 16/Sep/19 ]

Can you be more specific with what you mean by Linq discovering AsQueryable? Are you talking about Visual Studio behavior, or perhaps some other IDE?

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