[CSHARP-1773] Sample operator throws ArgumentException Created: 03/Oct/16 Updated: 03/Nov/16 Resolved: 03/Nov/16 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Linq |
| Affects Version/s: | 2.3 |
| Fix Version/s: | 2.4 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Attila Kisko | Assignee: | Craig Wilson |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Minor Change |
| Description |
This is coming from a relatively simple query: collection.AsQueryable().Where().OrderBy().Sample(); The reason for the exception is that 1. tho the operations in MongoQueryable are defined as IMongoQueryable<T> Operation(this IMongoQueryable<T>,...) Sample() creates the expression using Expression.Call, but its method signature does not "accept" the expression (as per the validations inside Expression.Call). The solution is to change the method signature to public static IMongoQueryable<TSource> Sample<TSource>(this IQueryable<TSource> source, long count) Not sure if this solution is acceptable, but haven't found any better way (without reimplementing all LINQ operations so they have IMongoQueryable as their Expression.Type) I have a pull request & a simple unit test which I can submit if you want it https://github.com/enyim/mongo-csharp-driver/commit/0910aa62b26a7c4460fa83ed03cb87e52a89c971 |
| Comments |
| Comment by Githook User [ 03/Nov/16 ] |
|
Author: {u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}Message: |
| Comment by Craig Wilson [ 02/Nov/16 ] |
|
Hi Attila, Sorry for the late response. In regards to your question, we do "reimplement" every operator in MongoQueryable. For instance: where -> https://github.com/mongodb/mongo-csharp-driver/blob/master/src/MongoDB.Driver/Linq/MongoQueryable.cs#L2810. However, the issue was this line: It should have looked like this: Will get it fixed. |
| Comment by Attila Kisko [ 31/Oct/16 ] |
|
anyone? |